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.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution{
	
	static long[] fact;
	static long[] p9, p10;
	
	
	
    public static void main(String[] args) throws IOException {
     
    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    	
    	fact = new long[20];
    	fact[0] = 1;
    	for(int i=1;i<20;i++) fact[i] = fact[i-1]*i;
    	
    	p9 = new long[19];
    	p9[0]=  1;
    	for(int i=1;i<19;i++) p9[i] = p9[i-1]*9;
    	
    	p10 = new long[19];
    	p10[0] = 1;
    	for(int i=1;i<19;i++) p10[i] = p10[i-1]*10;
    	
    		
    	int tt = fs.nextInt();
    	while(tt-->0) {
    		
    		long l = fs.nextLong(), r = fs.nextLong();
    		out.println(solve(r)-solve(l-1));
    		
    		
    	}
    	
    		
    		
    		
    	out.close();
    		
    }
    
   
    
    //return the number of required numbers less than equal to n
    static long solve(long n) {
    	return solve2(n, 1) + solve2(n, 2) + solve2(n, 3);
    }
    
    
    static long solve2(long n, int k) {
    	int d = numdig(n);
    	if(d<k) return 0;
    	
    	long ans = C(d, k)*p9[k];
    	int zCount = 0;
    	
    	for(int i=1;i<=d;i++) {
    		if(k-i+zCount<0) break;
    		long dig = (n/p10[d-i])%10;
    		ans -= (9-dig)*C(d-i, k-i+zCount)*p9[k-i+zCount];
    		if(dig==0) zCount++;
    	}
    	
    	return ans;
    }
    
    
    static int numdig(long n) {
    	int cnt = 0;
    	while(n>0) {
    		cnt++;
    		n /= 10;
    	}
    	return cnt;
    }
    
    static long C(int n, int r) {
    	if(r>n) return 0;
    	return fact[n]/(fact[r]*fact[n-r]);
    }
    
    
    static final Random random=new Random();
    	
    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort 
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }
   
  
    
    	
    	
    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 String nextLine() throws IOException {
    		return br.readLine();
    	}
    		
    	public int nextInt(){
    		return Integer.parseInt(next());
    	}
     
    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}
    		
    	public long nextLong() {
    		return Long.parseLong(next());
    	}
    		
    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }
   	
}