3032: QAQ Number

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:1 通过:1

题目描述

QAQ, the greatest mathematician of the 21st century, found a new number called QAQ Number. The QAQ Numbers are positive integers without leading zeros which satisfy the following conditions:

  • It has exactly $3k$ digits(k is a positive integer), and can be divided into three sections $a_{1}...a_{k}$, $a_{k+1}...a_{2k}$ and $a_{2k+1}...a_{3k}$.
  • Digits of the same section are the same. Explicitly, $a_{1} = a_{2} = ... = a_{k - 1} = a_{k}$, $a_{k + 1} = a_{k + 2} = ... = a_{2k - 1} = a_{2k}$, $a_{2k + 1} = a_{2k + 2} = ... = a_{3k - 1} = a_{3k}$.
  • The first and third sections are the same, which means $a_{1} = a_{2k + 1}$, $a_{2} = a_{2k + 2}$ , ... , $a_{k} = a_{3k}$.

For instance, 111222111, 919 and 666666 are QAQ Numbers, but 1111, 010 , 444455554443 are not.

Now QAQ wants to know how many QAQ Numbers are there in range [L, R](inclusive).

输入格式

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

i-th of each next T lines contains two numbers L and R ($1 \leq L \leq R \leq 10^{18}$).

输出格式

For each test case print one number.

输入样例 复制

3
1 100
101 999
1000 1000000000

输出样例 复制

0
90
180