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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C {
    
    static long[][] dp=new long[19][4];
    
    static long[] tenTo=new long[20];

    public static void main(String[] args) {
        FastScanner fs=new FastScanner();
        tenTo[0]=1;
        for (int i=1; i<19; i++) tenTo[i]=tenTo[i-1]*10;
        tenTo[19]=Long.MAX_VALUE;
        int T=fs.nextInt();
        for (int i=0; i<dp.length; i++)
        	Arrays.fill(dp[i], -1);
        for (int t=0; t<T; t++) {
            long l=fs.nextLong(), r=fs.nextLong();
            long ll=go(18, 3, true, (l-1));
            long rr=go(18, 3, true, r);
//            System.out.println("Less than "+l+": "+ll);
            long ans=rr-ll;
            System.out.println(ans);
        }
    }

    static long go(int digit, int nonzerosLeft, boolean bounded, long upperBound) {
//    	System.out.println("In digit: "+digit+" nozeros: "+nonzerosLeft+" bounded: "+bounded+" upperBound: "+upperBound);
    	if (nonzerosLeft<0) {
    		return 0;
    	}
        if (digit==-1) {
            return 1;
        }
        long total=0;
        if (!bounded) {
        	if (dp[digit][nonzerosLeft]!=-1)
        		return dp[digit][nonzerosLeft];
            if (nonzerosLeft>0) {
                total+=9*go(digit-1, nonzerosLeft-1, false, 0);
            }
            total+=go(digit-1, nonzerosLeft, false, 0);
            return dp[digit][nonzerosLeft]=total;
        }
        else {
            long real=upperBound%tenTo[digit+1]/tenTo[digit];
            for (int next=0; next<real; next++) {
                total+=go(digit-1, nonzerosLeft-(next==0?0:1), false, 0);
            }
            total+=go(digit-1, nonzerosLeft-(real==0?0:1), true, upperBound);
//            System.out.println("bounded in digit "+digit+" returning "+total+" real: "+real);
            return total;
        }
    }
    
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        
        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
        
        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) {
                a[i]=nextInt();
            }
            return a;
        }
        
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        
    }

}