P13819 [CodeChef] onoz
普及
题目描述

3:33
It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are identical, but it is not a valid time on a usual digital clock.
The above example was for a usual 24-hour format digital clock. Let's consider a more general clock, where an hour lasts M minutes and a day lasts H hours (therefore, the clock can show any number of hours between 0 and H-1, inclusive, and any number of minutes between 0 and M-1, inclusive). Both the hours and the minutes are shown without leading zeroes in decimal notation and their separator (e.g., ':') doesn't matter.
Can you tell how many minutes during a day will the digital clock have identical digits displayed on it?

Input

The first line of the input contains an integer T - the number of test cases.
Each of the next T lines contains two space-separated integers H and M for one test case.

Output
For each test case, output a single line corresponding to the answer of the problem.

Constraints

1 ≤ T ≤ 50
1 ≤ H, M ≤ 100

Example
Input:
6
24 60
34 50
10 11
10 12
11 11
1 1

Output:
19
20
10
11
10
1

Explanation
Example case 1. A clock shows two identical digits at times 0:0, 1:1, .., 9:9, three identical digits at times 11:1, 22:2, 1:11, 2:22, 3:33, 4:44, 5:55, and four identical digits at times 11:11 and 22:22. So, there are 19 minutes during which the time displayed by the clock will have identical digits.
Example case 2. Compared to the previous case, the clock doesn't show 5:55, but can show 33:3 and 33:33.
Example case 6. In this example, our day consists of one hour and one hour consists of one minute. Hence, the entire day is just 1 minute - the only time the digital clock will display is 0:0 during the entire day, (i.e. the entire hour, i.e. entire minute). And 0:0 has all digits identical, so the answer is 1.

输入格式

见题面

输出格式

见题面

样例输入
6 24 60 34 50 10 11 10 12 11 11 1 1
样例输出
19 20 10 11 10 1