atcoder#AGC057A. [AGC057A] Antichain of Integer Strings

[AGC057A] Antichain of Integer Strings

Score : 400400 points

Problem Statement

A set AA of positive integers is said to be good when it satisfies the following condition.

  • For any two distinct elements a,bAa, b \in A, the string representing aa in base ten is not a substring of the string representing bb in base ten.
What is a substring? A substring of a string is its contiguous subsequence. For example, 1, 12, and 23 are substrings of 123, while 21 and 13 are not.

You are given positive integers LL and RR. Find the maximum possible number of elements in a good set AA consisting of integers between LL and RR (inclusive).

We will give you TT test cases; solve each of them.

Constraints

  • 1T1041\leq T\leq 10^4
  • 1LR1091\leq L\leq R\leq 10^{9}

Input

Input is given from Standard Input in the following format:

TT

case1\text{case}_1

\vdots

caseT\text{case}_T

Each case is in the following format:

LL RR

Output

Print TT lines. The ii-th line should contain the answer for casei\text{case}_i.

3
3 8
3 18
1 1000
6
10
900

For the first two cases, the following are good sets AA with the maximum number of elements.

  • Case 11: A={3,4,5,6,7,8}A=\{3,4,5,6,7,8\}.
  • Case 22: A={3,4,6,8,9,10,11,12,15,17}A=\{3,4,6,8,9,10,11,12,15,17\}.