#P4109. [HEOI2015] 定价
[HEOI2015] 定价
Description
In the market, many goods are priced like 999 yuan, 4999 yuan, 8999 yuan. They are essentially no different from 1000 yuan, 5000 yuan, and 9000 yuan, but psychologically they make people feel much cheaper, so this is a common pricing strategy used by merchants. However, in your view, such prices are absurd. Therefore, you define the absurdity of a price ( is a positive integer) as follows:
- First, treat as a string of digits (without leading ).
- Then, if the last character of is , remove it. Repeat this process until the last character of is not .
- Let the length of be . If the last digit is , the absurdity is ; otherwise, it is .
For example, the absurdity of 850 is 3, for 880 it is 4, and the absurdity of 9999 is 8.
Now, you want to sell an idle item. The acceptable price is within the range . You want to choose a price with the lowest absurdity.
Input Format
The first line of input contains a positive integer , indicating the number of testdata.
Each test case is on a separate line and contains two space-separated positive integers , indicating the pricing interval.
Output Format
For each test case, output the result on a separate line. If the price with the lowest absurdity is not unique, output the smallest one.
3
998 1002
998 2002
4000 6000
1000
1000
5000
Hint
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号