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.*;
import java.math.*;
import java.util.*;

public class C {
    List<Integer> digit = new ArrayList<>();
    long[][][][] dp = new long[20][2][2][4];
    long dfs(int p, int les, int pref, int cnt) {
        if(cnt >= 4) return 0l;
        if(p == digit.size()) {
            if(pref == 1) {
                return 1l;
            }
            return 0l;
        }
        if(dp[p][les][pref][cnt] != -1) return dp[p][les][pref][cnt];
        int up = les == 0 ? digit.get(p) : 9;
        long ans = 0;
        for(int i = 0; i <= up; ++i) {
            ans += dfs(p + 1, les == 1 ? 1 : (i < up ? 1 : 0), pref == 1 ? 1 : (i > 0 ? 1 : 0), cnt + (i > 0 ? 1 : 0));
        }
        dp[p][les][pref][cnt] = ans;
        return ans;
    }
    long solve(long r) {
//        System.out.println("solve r:" + r);
//        System.out.flush();
        if(r == 0) return 0l;
        digit.clear();
        for(int i = 0; i < 20; ++i)
            for(int j = 0; j < 2; ++j)
                for(int k = 0; k < 2; ++k)
                    for(int t = 0; t < 4; ++t)
                        dp[i][j][k][t] = -1l;
        long t = r;
//        for(int i = 0; i < 20; ++i) {
//            digit.add((int)(t % 10));
//            t /= 10l;
//        }
        while(t > 0) {
            digit.add((int)(t % 10));
            t /= 10;
        }
        Collections.reverse(digit);
//        for(int i : digit) System.out.println(i); System.out.println("");
        return dfs(0, 0, 0, 0);
    }
    public void run() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 0; i < n; ++i) {
            long x = scan.nextLong(), y = scan.nextLong();
            System.out.println(solve(y) - solve(x-1));
        }
    }

    public static void main(String[] args) {
        new C().run();
    }
}