#P4193. 数字

数字

Description

Xiao D's favorite numbers have the following property.

Let nn be a positive integer, let S(n)S(n) be the sum of the digits of nn, and define D(n)D(n) as follows.

$$D(n) = \begin{cases} \displaystyle S(n) & S(n) < 10 \\ \displaystyle D(S(n)) & S(n) > 10 \end{cases}$$

Every number that Xiao D likes can be written in the form x×D(x)x \times D(x) (that is, if a number AA is liked, then there exists a number xx such that A=x×D(x)A = x \times D(x)).

Xiao D wants to know how many numbers he likes in the interval [L,R][L, R].

Input Format

The first line contains an integer TT, the number of test cases.

The next TT lines each contain two numbers LL and RR (the interval is guaranteed to be valid), representing the query [L,R][L, R].

Output Format

Output TT lines, each with a single number, indicating how many numbers Xiao D likes appear in this interval.

You will receive full score for a test point if and only if your output exactly matches the standard output.

3
1 5
3 9
8 8
2
2
0

Hint

For 100%100\% of the testdata, L,R1018L, R \le 10^{18} and T20T \le 20.

Translated by ChatGPT 5