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.*;

public class CC50 {

    static int calc(long x) {
        String number = String.valueOf(x);
        int prefLen = 0;
        int sufLen = number.length();
        int nonZeroCnt = 0;
        int ans = 0;
        for(;prefLen < number.length(); prefLen++, sufLen--) {
            char dig = number.charAt(prefLen);
            if(dig == '0') {
                continue;
            } else {
                // set dig to 0
                ans += variants(sufLen - 1, 3 - nonZeroCnt);
                if(dig != '1') {
                    ans += (dig - '1') * variants(sufLen - 1, 2 - nonZeroCnt);
                }
                nonZeroCnt++;
            }
        }
        if(nonZeroCnt <= 3) {
            ans++;
        }
        return ans;
    }

    static int variants(int sufLen, int nonZeroLeft) {
        int ans = 0;
        for(int i = 0; i <= Math.min(nonZeroLeft, sufLen); ++i) {
            ans += comb(i, sufLen) * Math.pow(9, i);
        }
        return ans;
    }

    static int comb(int k, int n) {
        return c[k][n];
    }

    static int c[][] = new int[4][20];
    static {
        for(int i = 0; i < 4; ++i) {
            c[i][i] = 1;
        }
        for(int i = 0; i < 20; ++i) {
            c[0][i] = 1;
            for(int j = 1; j < 4 && j < i; ++j) {
                c[j][i] = c[j-1][i-1] + c[j][i-1];
            }
        }
//        for(int i = 0; i < 4; ++i) {
//            System.out.println(Arrays.toString(c[i]));
//        }
    }


    public static void main(String[] args) {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out);

        int t = in.nextInt();
        while(t-- > 0) {
            long l = in.nextLong();
            long r = in.nextLong();
            out.println(calc(r) - calc(l - 1));
            out.flush();
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}