Problem: Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.

You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase.

Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001


Output

1000
1
0
2

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class ClassyNumbers {
    static long[][][] dp = new long[20][20][2]; // 18 position.. count contains no more than 3 non-zero digits.. tight can be 0/1
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        StringBuffer sb = new StringBuffer();
        while (t-->0){
            String[] input = br.readLine().split(" ");
            long l = Long.parseLong(input[0]) - 1;
            long r = Long.parseLong(input[1]);

            String a = String.valueOf(l);
            String b = String.valueOf(r);

            fillDp(dp);
            long result = solve(b,0,0,1);
            fillDp(dp);
            result = result - solve(a,0,0,1);

            sb.append(result+"\n");

        }
        System.out.print(sb);
    }

    static long solve(String input,int position,int count,int tight){
        if (position==input.length()){
            return 1;
        }
        else if (dp[position][count][tight]!=-1) {
            return dp[position][count][tight];
        }

        else if(tight==1){
            long result = 0;
            for (int i=0;i<=input.charAt(position)-'0';i++){
                int countUpdate = count + ((i>0)?1:0);
                if (countUpdate<=3){
                    if (i==input.charAt(position)-'0'){
                        result += solve(input,position+1,countUpdate,1);
                    }
                    else{
                        result += solve(input,position+1,countUpdate,0);
                    }
                }
            }
            dp[position][count][tight] = result;
            return result;
        }

        else{
            long result = 0;
            for (int i=0;i<=9;i++){
                int countUpdate = count + ((i>0)?1:0);
                if (countUpdate<=3)
                    result += solve(input,position+1,countUpdate,0);
            }
            dp[position][count][tight] = result;
            return result;
        }

    }

    static void fillDp(long[][][] dp){
        for (long[][] x : dp)
            for (long[] y: x)
                Arrays.fill(y,-1);
    }
}