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.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    static long memo[][][];
    static int[] n;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int tc = sc.nextInt();
        while (tc-- > 0) {
            long left = sc.nextLong();
            long right = sc.nextLong();
            out.println(-solve(left) + solve(right) + add(left + ""));
        }
        out.flush();
        out.close();
    }

    static int add(String s) {
        int c = 0;
        for (int i = s.length() - 1; i >= 0; i--)
            if (s.charAt(i) != '0') c++;
        if (c <= 3) return 1;
        return 0;
    }

    static long solve(long x) {
        memo = new long[19][2][19];
        for (long[][] a : memo)
            for (long[] b : a)
                Arrays.fill(b, -1);
        int i = fillnum(x);
        return dp(i, 1, 0) - 1;
    }

    static int fillnum(long x) {
        n = new int[19];
        int idx = 18;
        String s = "" + x;
        int c = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            n[idx--] = Character.getNumericValue(s.charAt(i));
            if (s.charAt(i) != '0') c++;
        }
        return idx + 1;
    }

    static long dp(int i, int isequal, int nonzeros) {
        if (nonzeros > 3) return 0;
        if (i == 19)
            return 1;
        if (memo[i][isequal][nonzeros] != -1)
            return memo[i][isequal][nonzeros];
        long cnt = 0;
        int digit = n[i];
        for (int j = 0; j < 10; j++) {
            if (isequal == 1 && j == digit) {
                cnt += dp(i + 1, 1, (j == 0) ? nonzeros : nonzeros + 1);
                continue;
            }
            if (isequal == 0)
                cnt += dp(i + 1, isequal, (j == 0) ? nonzeros : nonzeros + 1);
            if (isequal == 1 && j < digit)
                cnt += dp(i + 1, 0, (j == 0) ? nonzeros : nonzeros + 1);
        }
        return memo[i][isequal][nonzeros] = cnt;
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}