Dictionary Survey

No attempts yetTime limit3sMemory limit256 MB

Problem

Jihak wrote every natural number from AA to BB into a dictionary, one number per page, so the dictionary has BA+1B - A + 1 pages. The numbers are not ordered by value, they are ordered lexicographically, which means their decimal spellings are compared character by character. For A=4A = 4 and B=12B = 12 the pages carry 10, 11, 12, 4, 5, 6, 7, 8, 9 in that order.

Jihak handed the dictionary to Suchan and told him only that it holds consecutive natural numbers in lexicographic order. Suchan wants to work out which numbers are inside, that is, the values of AA and BB. The pages carry no page numbers, so he can only read them one at a time from the front. Once he has read the last page the cover appears, so at that moment he knows the dictionary is over.

Given AA and BB, find the smallest number of pages Suchan has to read before both AA and BB are certain.

Input

The first line contains the number of test cases TT (1T1051 \le T \le 10^5). Each of the next TT lines holds one test case: two integers AA and BB (1AB10181 \le A \le B \le 10^{18}) separated by a space. This means Jihak built the dictionary from the natural numbers between AA and BB inclusive.

Output

For each test case, print the minimum number of pages Suchan has to read on its own line.

Hint

For A=1A = 1 and B=11B = 11 the pages come in the order 1, 10, 11, 2, 3, 4, 5, 6, 7, 8, 9. After four pages Suchan has seen 1, 10, 11, 2, and any BB of 12 or more would have put 12 right after 11, so B=11B = 11 is settled.

For A=5A = 5 and B=13B = 13 the order is 10, 11, 12, 13, 5, 6, 7, 8, 9.

For A=3A = 3 and B=5B = 5 the order is 3, 4, 5. Only after the third page, when the cover appears, does Suchan learn that 6 is absent.