CF1808A.Lucky Numbers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Olympus City recently launched the production of personal starships. Now everyone on Mars can buy one and fly to other planets inexpensively.

Each starship has a number —some positive integer xx . Let's define the luckiness of a number xx as the difference between the largest and smallest digits of that number. For example, 142857142857 has 88 as its largest digit and 11 as its smallest digit, so its luckiness is 81=78-1=7 . And the number 111111 has all digits equal to 11 , so its luckiness is zero.

Hateehc is a famous Martian blogger who often flies to different corners of the solar system. To release interesting videos even faster, he decided to buy himself a starship. When he came to the store, he saw starships with numbers from ll to rr inclusively. While in the store, Hateehc wanted to find a starship with the luckiest number.

Since there are a lot of starships in the store, and Hateehc can't program, you have to help the blogger and write a program that answers his question.

输入格式

The first line contains an integer tt ( 1t100001 \le t \le 10\,000 ) —the number of test cases.

Each of the following tt lines contains a description of the test case. The description consists of two integers ll and rr ( 1lr1061 \le l \le r \le 10^6 ) — the largest and smallest numbers of the starships in the store.

输出格式

Print tt lines, one line for each test case, containing the luckiest starship number in the store.

If there are several ways to choose the luckiest number, output any of them.

输入输出样例

  • 输入#1

    5
    59 63
    42 49
    15 15
    53 57
    1 100

    输出#1

    60
    49
    15
    57
    90

说明/提示

Let's look at two test examples:

  • the luckiness of the number 5959 is 95=49 - 5 = 4 ;
  • the luckiness of 6060 equals 60=66 - 0 = 6 ;
  • the luckiness of 6161 equals 61=56 - 1 = 5 ;
  • the luckiness of 6262 equals 62=46 - 2 = 4 ;
  • the luckiness of 6363 is 63=36 - 3 = 3 .

Thus, the luckiest number is 6060 .In the fifth test example, the luckiest number is 9090 .

首页