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:
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {


        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            for (int i = 0; i < dp.length; i++) {
                Arrays.fill(dp[i], -1);
            }
            int T = sc.nextInt();
            for (int i = 0; i < T; i++) {
                long l = sc.nextLong();
                long r = sc.nextLong();
                long ql = solve(l - 1);
                long qr = solve(r);
                pw.println(qr - ql);
            }
        }

        public long solve(long a) {
            int idx = 1;
            while (a != 0) {
                num[idx++] = (int) (a % 10);
                a /= 10;
            }
            return digitDP(idx - 1, 0,  1);
        }

        int[] num = new int[22];
        long[][] dp = new long[22][5];
        public long digitDP(int pos, int usedNone0, int isEq) {
            if (isEq == 0 && dp[pos][usedNone0] != -1) {
                return dp[pos][usedNone0];
            }
            if (usedNone0 == 3) return 1;
            if (pos == 0) {
                return 1;
            }
            int end = isEq == 0 ? 9 : num[pos];
            long sum = 0;
            for (int i = 0; i <= end; i++) {
                if (i == 0) {
                    sum += digitDP(pos - 1, usedNone0, isEq == 1 && i == end ? 1 : 0);
                } else {
                    sum += digitDP(pos - 1, usedNone0 + 1, isEq == 1 && i == end ? 1 : 0);
                }
            }
            return isEq == 1 ? sum : (dp[pos][usedNone0] = sum);

        }


    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

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

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

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

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

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

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}