CF1036C.Classy Numbers

传统题 时间 2000 ms 内存 256 MiB 9 尝试 21 已通过 7 标签

Classy Numbers

Let's call some positive integer classy if its decimal representation contains no more than 33 non-zero digits. For example, numbers 44, 200000200000, 1020310203 are classy and numbers 42314231, 102306102306, 72774200007277420000 are not.

You are given a segment [L;R][L; R]. Count the number of classy integers xx such that LxRL \le x \le R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer TT (1T1041 \le T \le 10^4) — the number of segments in a testcase.

Each of the next TT lines contains two integers LiL_i and RiR_i (1LiRi10181 \le L_i \le R_i \le 10^{18}).

Output

Print TT lines — the ii-th line should contain the number of classy integers on a segment [Li;Ri][L_i; R_i].

Samples

4
1 1000
1024 1024
65536 65536
999999 1000001
1000
1
0
2

在线编程 IDE

建议全屏模式获得最佳体验