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

public class Main {
    
    
    static InputReader in;
    static PrintWriter out;
        
    public static void main(String[] args) throws IOException{
        //InputStream ins = new FileInputStream("E:\\rush.txt");
        InputStream ins = System.in;
        in = new InputReader(ins);
        out = new PrintWriter(System.out);
        //code start from here
        new Task().solve(in, out);
        out.close();
    }
    
    static int N = 700000;
    static class Task{
        TreeSet<Long> myset = new TreeSet<Long>();
        long a[] = new long[N+10];
        int T,n;
        long l,r;
        
        void dfs(long cur,int num,int dep) {
        	if (dep==18) {
        		if (cur>0) myset.add(cur);	
        		return;
        	}
        	if (num<3) {
        		for (int j = 1;j <= 9;j++)
        			dfs(cur*10+j,num+1,dep+1);
        	}
        	dfs(cur*10,num,dep+1);
        }
        
        int get_least_gore(long x) {
        	int l = 1,r = n,temp = 1;
        	while (l<=r) {
        		int mid = (l+r)/2;
        		if (a[mid]>=x) {
        			temp = mid;
        			r = mid - 1;
        		}else l = mid + 1;
        	}
        	return temp;
        }
        
        int get_last_lore(long x) {
        	int l = 1,r = n,temp = 1;
        	while (l<=r) {
        		int mid = (l+r)/2;
        		if (a[mid]<=x) {
        			temp = mid;
        			l = mid + 1;
        		}else r = mid - 1;
        	}
        	return temp;
        }
        
        public void solve(InputReader in,PrintWriter out) {
        	myset.add((long)1e18);
        	dfs(0,0,0);
        	n = myset.size();
        	Iterator<Long> it = myset.iterator();
        	int j = 1;
        	while (it.hasNext()) {
        		a[j] = it.next();
        		j++;
        	}
        	T = in.nextInt();
        	for (int ii = 1;ii <= T;ii++) {
        		l = in.nextLong();r = in.nextLong();
        		int idx1 = get_least_gore(l);
        		int idx2 = get_last_lore(r);
        		out.println(idx2-idx1+1);
        	}
        }
    }

    

    static class InputReader{
        public BufferedReader br;
        public StringTokenizer tokenizer;
        
        public InputReader(InputStream ins) {
            br = new BufferedReader(new InputStreamReader(ins));
            tokenizer = null;
        }
        
        public String next(){
            while (tokenizer==null || !tokenizer.hasMoreTokens()) {
                try {
                tokenizer = new StringTokenizer(br.readLine());
                }catch(IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
        	return Long.parseLong(next());
        }
    }
}