310272: CF1808A. Lucky Numbers

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Lucky Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

Input

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.

Output

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.

ExampleInput
5
59 63
42 49
15 15
53 57
1 100
Output
60
49
15
57
90
Note

Let's look at two test examples:

  • the luckiness of the number $59$ is $9 - 5 = 4$;
  • the luckiness of $60$ equals $6 - 0 = 6$;
  • the luckiness of $61$ equals $6 - 1 = 5$;
  • the luckiness of $62$ equals $6 - 2 = 4$;
  • the luckiness of $63$ is $6 - 3 = 3$.
Thus, the luckiest number is $60$.

In the fifth test example, the luckiest number is $90$.

Input

题意翻译

定义一个数的幸运值为这个数中最大数字与最小数字的差。例如数字 $142857$ 的幸运值为 $8-1=7$ 。现给出 $T$ 组区间 $[l,r]$ ,对于每组数据输出区间中幸运值最大的数字,若有多种答案输出一种即可。 $T \leq 10\ 000$,$1 \leq l \leq r \leq 10^6$ 。

Output

题目大意:
奥林巴斯城最近开始生产个人星际飞船,现在火星上的每个人都可以买一架并低成本飞往其他星球。每架星际飞船都有一个数字——某个正整数 \( x \)。定义一个数字 \( x \) 的“幸运度”为该数字的最大数字和最小数字之差。例如,数字 142857 的最大数字是 8,最小数字是 1,所以它的幸运度是 \( 8-1=7 \)。而数字 111 的所有数字都是 1,所以它的幸运度是零。

Hateehc 是一位著名的火星博主,他经常飞往太阳系的不同角落。为了更快发布有趣的视频,他决定买一架星际飞船。当他来到商店时,他看到了从 \( l \) 到 \( r \) 的星际飞船数字。在商店里,Hateehc 想要找到一架数字最幸运的星际飞船。

由于商店里有很多星际飞船,而 Hateehc 不会编程,你需要帮助这位博主编写一个程序来回答他的问题。

输入输出数据格式:
输入:
第一行包含一个整数 \( t \)(\( 1 \le t \le 10,000 \))——测试用例的数量。
接下来的 \( t \) 行,每行包含一个测试用例的描述。描述由两个整数 \( l \) 和 \( r \)(\( 1 \le l \le r \le 10^6 \))组成——商店中星际飞船的最大和最小数字。

输出:
打印 \( t \) 行,每行对应一个测试用例,输出商店中最幸运的星际飞船数字。
如果有多种选择最幸运数字的方式,输出其中任意一种。题目大意: 奥林巴斯城最近开始生产个人星际飞船,现在火星上的每个人都可以买一架并低成本飞往其他星球。每架星际飞船都有一个数字——某个正整数 \( x \)。定义一个数字 \( x \) 的“幸运度”为该数字的最大数字和最小数字之差。例如,数字 142857 的最大数字是 8,最小数字是 1,所以它的幸运度是 \( 8-1=7 \)。而数字 111 的所有数字都是 1,所以它的幸运度是零。 Hateehc 是一位著名的火星博主,他经常飞往太阳系的不同角落。为了更快发布有趣的视频,他决定买一架星际飞船。当他来到商店时,他看到了从 \( l \) 到 \( r \) 的星际飞船数字。在商店里,Hateehc 想要找到一架数字最幸运的星际飞船。 由于商店里有很多星际飞船,而 Hateehc 不会编程,你需要帮助这位博主编写一个程序来回答他的问题。 输入输出数据格式: 输入: 第一行包含一个整数 \( t \)(\( 1 \le t \le 10,000 \))——测试用例的数量。 接下来的 \( t \) 行,每行包含一个测试用例的描述。描述由两个整数 \( l \) 和 \( r \)(\( 1 \le l \le r \le 10^6 \))组成——商店中星际飞船的最大和最小数字。 输出: 打印 \( t \) 行,每行对应一个测试用例,输出商店中最幸运的星际飞船数字。 如果有多种选择最幸运数字的方式,输出其中任意一种。

加入题单

算法标签: