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.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class cf1036c {
    public static void main(String[] args) throws IOException {
        List<Long> classy = getClassyNumbers();
        IO in = new IO();
        int T = in.nextInt();
        for (int testCase = 1; testCase <= T; testCase++) {
            long L = in.nextLong();
            long R = in.nextLong();
            int idx1 = Collections.binarySearch(classy, L);
            if (idx1 < 0) {
                idx1 = ~idx1;
            }
            int idx2 = Collections.binarySearch(classy, R);
            if (idx2 < 0) {
                idx2 = ~idx2 - 1;
            }
            System.out.println(idx2 - idx1 + 1);
        }
    }

    private static List<Long> getClassyNumbers() {
        List<Long> list = new ArrayList<>();
        for (long i = 1; i < 1000; i++) {
            list.add(i);
        }
        for (int power = 3; power < 18; power++) {
            for (int first = 1; first < 10; first++) {
                long n = first;
                for (int second = 1; second < 10; second++) {
                    for (int p1 = 1; p1 <= power; p1++) {
                        for (int third = 1; third < 10; third++) {
                            for (int p2 = p1 + 1; p2 <= power; p2++) {
                                long num = n;
                                for (int i = 1; i <= power; i++) {
                                    num *= 10;
                                    if (i == p1) {
                                        num += second;
                                    } else if (i == p2) {
                                        num += third;
                                    }
                                }
                                list.add(num);
                            }
                        }
                        long num = n;
                        for (int i = 1; i <= power; i++) {
                            num *= 10;
                            if (i == p1) {
                                num += second;
                            }
                        }
                        list.add(num);
                    }
                }
                for (int i = 1; i <= power; i++) {
                    n *= 10;
                }
                list.add(n);
            }
        }
        list.add(1000000000000000000L);
        Collections.sort(list);
        return list;
    }

    private static class IO {
        private BufferedReader in;
        private Queue<String> tokens;
        private boolean clearedLine;

        public IO() {
            this(System.in);
        }

        public IO(InputStream stream) {
            this(new InputStreamReader(stream));
        }

        public IO(Reader reader) {
            this(new BufferedReader(reader));
        }

        public IO(BufferedReader reader) {
            this.in = reader;
            tokens = new ArrayDeque<>();
            clearedLine = false;
        }

        private void addTokens() throws IOException {
            StringTokenizer tk = new StringTokenizer(in.readLine());
            while (tk.hasMoreTokens()) {
                tokens.add(tk.nextToken());
            }
        }

        public String nextLine() throws IOException {
            if (tokens.isEmpty() && clearedLine) {
                addTokens();
            }
            String result = String.join(" ", tokens);
            tokens.clear();
            clearedLine = true;
            return result;
        }

        public Stream<String> nextLineTokenStream() throws IOException {
            if (tokens.isEmpty() && clearedLine) {
                addTokens();
            }
            Stream.Builder<String> streamBuilder = Stream.builder();
            while (!tokens.isEmpty()) {
                streamBuilder.add(tokens.remove());
            }
            clearedLine = true;
            return streamBuilder.build();
        }

        public String next() throws IOException {
            if (tokens.isEmpty()) {
                addTokens();
            }
            clearedLine = false;
            return tokens.remove();
        }

        public <T> T next(Function<String, T> converter) throws IOException {
            return converter.apply(next());
        }

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

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

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

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

        public BigInteger nextBigInteger() throws IOException {
            return new BigInteger(next());
        }

        public BigInteger nextBigInteger(int radix) throws IOException {
            return new BigInteger(next(), radix);
        }
    }
}