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.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

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

    static class Spoj_dp {
        long[][][] dp = new long[19][2][4];
        ArrayList<Long> list = new ArrayList<>();
        int size = 0;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int q = in.ni();
            while (q-- > 0) {
                long l = in.nl();
                long r = in.nl();
                out.println(fun(r) - fun(l - 1));
            }
        }

        long func(int idx, int tight, int non_zeros) {
            if (idx == size) {
                return 1;
            }
            if (dp[idx][tight][non_zeros] != -1) {
                return dp[idx][tight][non_zeros];
            }
            long ret = 0;
            if (tight == 1) {
                for (long i = 0; i <= list.get(idx); i++) {
                    int non_zero = 1;
                    if (i == 0)
                        non_zero = 0;
                    if ((non_zero + non_zeros) <= 3) {
                        if (i < list.get(idx)) {
                            ret += func(idx + 1, 0, non_zeros + non_zero);
                        } else if (i == list.get(idx)) {
                            ret += func(idx + 1, 1, non_zeros + non_zero);
                        }
                    }
                }
            } else {
                for (long i = 0; i <= 9; i++) {
                    int non_zero = 1;
                    if (i == 0)
                        non_zero = 0;
                    if ((non_zero + non_zeros) <= 3) {
                        ret += func(idx + 1, 0, non_zeros + non_zero);
                    }
                }
            }
            return dp[idx][tight][non_zeros] = ret;
        }

        long fun(long x) {
            for (int i = 0; i < 19; i++) {
                for (int j = 0; j < 2; j++) {
                    Arrays.fill(dp[i][j], -1);
                }
            }
            if (x == 0) {
                return 1;
            }
            list.clear();
            while (x > 0) {
                long rem = x % 10;
                x /= 10;
                list.add(rem);
            }
            //System.out.println(list);
            Collections.reverse(list);
            size = list.size();
            //System.out.println(list);
            long ans = func(0, 1, 0);
            return ans;
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

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

        public int ni() {
            return Integer.parseInt(n());
        }

        public long nl() {
            return Long.parseLong(n());
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}