Under construction

Still being built. Things may change

Palindromic Numbers

Time limit2sMemory limit512 MB

Summary
Count integers x in [L, R] for which both x-1 and x+1 are palindromes, with leading zeros allowed, for up to 2000 queries with R up to 10^18.
Level

Medium7 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Statement

Vasya loves studying interesting classes of numbers. Today he is studying palindromic numbers.

Vasya calls a number palindromic if it reads the same from left to right and from right to left. Vasya also allows adding any number of leading zeros (possibly none) to a number. For example, the numbers 22, 4554, 12321, and 5050 are palindromic. In particular, 5050 needs one leading zero to become 05050, which reads the same from both ends.

Among other things, Vasya is interested in palindromic numbers that differ by 2. To study them, Vasya considers numbers xx such that both x−1x-1 and x+1x+1 are palindromic. Vasya calls these numbers between-palindromic. Vasya wants to count the between-palindromic numbers xx in the segment [Lk,Rk][L_k, R_k], inclusive, for several segments.

Help Vasya with this task.

Input

The input file contains several segments that interest Vasya. The first line contains one integer TT (1≤T≤20001 \le T \le 2000), the number of segments. Each of the next TT lines contains two integers LkL_k and RkR_k (1≤Lk≤Rk≤10181 \le L_k \le R_k \le 10^{18}), the bounds of the segment.

Output

Print TT lines. On the kk-th line, print one integer: the number of between-palindromic numbers in the segment from LkL_k to RkR_k, inclusive.

Hint

The palindromic numbers between 17 and 24 are 20 and 22. So the only between-palindromic number in the segment [18,23][18, 23] is 21. In the second example, 21 also fits. The palindromic numbers between 49 and 56 are 50 and 55. There are no between-palindromic numbers in the segment [50,55][50, 55].

Examples1

  1. Example 1

    Input
    3
    18 23
    21 21
    50 55
    
    Expected output
    1
    1
    0