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.util.HashSet;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class CClassyNumbers {
        static ArrayList<Long> arrayList;

        public void solve(int testNumber, Scan in, PrintWriter out) {
            int a[] = new int[18];
            arrayList = new ArrayList<>();
            for (int i = 0; i < 18; i++) {
                for (int j = 1; j <= 9; j++) {
                    int h = a[i];
                    a[i] = j;
                    arrayList.add(create(a));
                    a[i] = h;
                }
            }
            HashSet<Long> set = new HashSet<>();
            for (int i = 0; i < arrayList.size(); i++) {
                set.add(arrayList.get(i));
            }
            int g = arrayList.size();
            for (int i = 0; i < g; i++) {
                for (int j = i; j < g; j++) {
                    if (!set.contains(arrayList.get(i) + arrayList.get(j))) {
                        set.add(arrayList.get(i) + arrayList.get(j));
                        arrayList.add(arrayList.get(i) + arrayList.get(j));
                    }
                }
            }
            for (int i = 0; i < g; i++) {
                for (int j = i; j < g; j++) {
                    for (int k = j; k < g; k++) {
                        if (!set.contains(arrayList.get(k) + arrayList.get(i) + arrayList.get(j))) {
                            set.add(arrayList.get(k) + arrayList.get(i) + arrayList.get(j));
                            arrayList.add(arrayList.get(k) + arrayList.get(i) + arrayList.get(j));
                        }
                    }
                }
            }
            Collections.sort(arrayList);
            int q = in.scanInt();
            while (q-- > 0) {
                long l = in.scanLong();
                long r = in.scanLong();
                int h = binarysearchl(l, 0, arrayList.size() - 1);
                int j = binarysearchu(r, 0, arrayList.size() - 1);
                out.println(j - h + 1);
            }

        }

        static int binarysearchl(long value, int l, int r) {
            int mid = l + (r - l) / 2;
            if (l > r) {
                return l;
            }
            if (value == arrayList.get(mid)) {
                return mid;
            } else if (arrayList.get(mid) < value) {
                return binarysearchl(value, mid + 1, r);
            } else {
                return binarysearchl(value, l, mid - 1);
            }
        }

        static int binarysearchu(long value, int l, int r) {
            int mid = l + (r - l) / 2;
            if (l > r) {
                return r;
            }
            if (value == arrayList.get(mid)) {
                return mid;
            } else if (arrayList.get(mid) < value) {
                return binarysearchu(value, mid + 1, r);
            } else {
                return binarysearchu(value, l, mid - 1);
            }
        }

        static long create(int[] a) {
            long ans = 0;
            long k = 1;
            for (int i = 0; i < 18; i++) {
                ans = ans + k * a[i];
                k *= 10;
            }
            return ans;
        }

    }

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

        public Scan(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;
        }

    }
}