A - Antichain of Integer Strings Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

正整数からなる集合 AA は次の条件を満たすとき、良い集合であるといいます。

  • 任意の相異なる 22 要素 a,bAa, b \in A に対して、aa1010 進法表記した文字列は、bb1010 進法表記した文字列の部分文字列ではない
部分文字列とは? 部分文字列とは連続する部分列のことを指します。例えば 1, 12, 23123 の部分文字列ですが、2113123 の部分文字列ではありません。


正整数 L,RL, R が与えられます。LL 以上 RR 以下の整数からなる良い集合 AA の要素数の最大値を求めてください。

TT 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

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

入力

入力は以下の形式で標準入力から与えられます。

TT
case1\text{case}_1
\vdots
caseT\text{case}_T

各テストケースは以下の形式で与えられます。

LL RR

出力

TT 行出力してください。ii 行目には、casei\text{case}_i に対する答えを出力してください。


入力例 1Copy

Copy
3
3 8
3 18
1 1000

出力例 1Copy

Copy
6
10
900

はじめの 22 つのテストケースについて、例えば次の AA が要素数が最大であるような良い集合となります。

  • 11 つめのテストケース:A={3,4,5,6,7,8}A=\{3,4,5,6,7,8\}.
  • 22 つめのテストケース:A={3,4,6,8,9,10,11,12,15,17}A=\{3,4,6,8,9,10,11,12,15,17\}.

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.


Sample Input 1Copy

Copy
3
3 8
3 18
1 1000

Sample Output 1Copy

Copy
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\}.


2025-03-28 (Fri)
19:33:43 +00:00