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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CClassyNumbers solver = new CClassyNumbers();
        solver.solve(1, in, out);
        out.close();
    }

    static class CClassyNumbers {
        long[][][] dp;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int t = in.scanInt();
            while (t-- > 0) {
                dp = new long[20][20][2];
                long l = in.scanLong();
                long r = in.scanLong();
                for (int i = 0; i < 20; i++) {
                    for (int j = 0; j < 20; j++) {
                        dp[i][j][0] = -1;
                        dp[i][j][1] = -1;
                    }
                }
                ArrayList<Integer> L = getDigits(l - 1);
                long ll = findit(L.size() - 1, 0, 1, L);
                ArrayList<Integer> R = getDigits(r);
                long rr = findit(R.size() - 1, 0, 1, R);
                out.println(rr - ll);


            }
        }

        ArrayList<Integer> getDigits(long x) {
            ArrayList<Integer> digits = new ArrayList<>();
            while (x > 0) {
                digits.add((int) (x % 10));
                x /= 10;
            }
            return digits;
        }

        long findit(int idx, int sum, int tight, ArrayList<Integer> digit) {

            if (idx == -1) {
                if (sum <= 3) return 1;
                else return 0;
            }
            if (dp[idx][sum][tight] != -1 && tight != 1) {
                return dp[idx][sum][tight];
            }
            long ret = 0;
            int k = (tight == 1) ? digit.get(idx) : 9;
            for (int i = 0; i <= k; i++) {
                int newTight = (digit.get(idx) == i) ? tight : 0;
                ret += findit(idx - 1, sum + (i == 0 ? 0 : 1), newTight, digit);
            }
            if (tight != 1) dp[idx][sum][tight] = ret;
            return ret;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

    }
}