Jihak wrote every natural number from A to B into a dictionary, one number per page, so the dictionary has B−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=4 and B=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 A and B. 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 A and B, find the smallest number of pages Suchan has to read before both A and B are certain.
The first line contains the number of test cases T (1≤T≤105). Each of the next T lines holds one test case: two integers A and B (1≤A≤B≤1018) separated by a space. This means Jihak built the dictionary from the natural numbers between A and B inclusive.
For each test case, print the minimum number of pages Suchan has to read on its own line.
For A=1 and B=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 B of 12 or more would have put 12 right after 11, so B=11 is settled.
For A=5 and B=13 the order is 10, 11, 12, 13, 5, 6, 7, 8, 9.
For A=3 and B=5 the order is 3, 4, 5. Only after the third page, when the cover appears, does Suchan learn that 6 is absent.