题库练习 Lucky Numbers
← 上一题 下一题 →

A15801 | Lucky Numbers

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 $x$ . Let's define the luckiness of a number $x$ as the difference between the largest and smallest digits of that number. For example, $142857$ has $8$ as its largest digit and $1$ as its smallest digit, so its luckiness is $8-1=7$ . And the number $111$ has all digits equal to $1$ , 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 $l$ to $r$ 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.

![](/uploads/acgo/image/a398f24eb8ef44ef_28f2a005eea0.jpeg)

输入格式

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

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

输出格式

Print $t$ 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
C++ 编辑器
输入
输出