#P7791. X Number

X Number

X Number

Problem Description

Teitoku loves many different kinds of numbers, and today Little W wants him to classify some positive integers into different categories. There are 1111 categories, numbered from 00 to 1010. For each positive integer xx, if there exists only one type of digit dd (0d9)(0 \leq d \leq 9) that occurs in xx with the highest frequency, then we say xx should be classified into category dd, or otherwise, in case such digit doesn't exist, we say xx should be classified into category 1010. For example, ● 111223111223 should be classified into category 11 since digit 11 occurs three times, and digits 22 and 33 occur less than three times respectively, and ● 33455443345544 should be classified into category 44 since digit 44 occurs three times, and digits 33 and 55 occur less than three times respectively, and ● 112233112233 should be classified into category 1010 since digits 11, 22 and 33 occur twice respectively. Little W doesn't care about category 1010 and he just wants Teitoku to tell him the number of integers ranged from ll to rr that should be classified to another category dd. However, Teitoku can hardly solve this problem, so he asks you for help.

Input

There are several test cases. The first line contains an integer TT (1T1000)(1 \leq T \leq 1000), denoting the number of test cases. Then follow all the test cases. For each test case, the only line contains three integers ll, rr and dd (1lr1018,0d9)(1 \leq l \leq r \leq 10^{18}, 0 \leq d \leq 9), representing a problem.

Output

For each test case, output in one line the number of integers ranged from ll to rr that should be classified to category dd.

Sample Input

3
1 10 1
1 11 1
1 100 0

Sample Output

1
2
1

Hint

For the sample cases, 1 and 11 are in category 1, 100 is in category 0 and 10 is in category 10.

Source

2020 Multi-University Training Contest 3