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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;


public class Main {

	static class Task {
		
		int NN = 200005;
		int MOD = 1000000007;;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;
		
		String c218(String s) {
			String ret = "";
			for(int i=0;i<20-s.length();++i) {
				ret += "0";
			}
			for(int i=0;i<s.length();++i) {
				ret += s.charAt(i);
			}
			return ret;
		}
		
		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-- > 0) {
				String L =  c218(in.next()), R = c218(in.next());
				out.println(f(0, 0, 0, R) - f(0, 0, 0, L) + isOk(L));
			}
		}
		
		int isOk(String s) {
			int cnt = 0;
			for(int i=0;i<s.length();++i) {
				if(s.charAt(i) == '0')
					continue;
				++cnt;
			}
			if(cnt > 3)
				return 0;
			return 1;
		}
		
		long g(long n, long k) {
			long [] ncr = new long[] {
				1L,
				n,
				n*(n-1L)/2L,
				n*(n-1L)*(n-2L)/6L
			};
			long nine = 1;
			long count =  0;
			for(long i=0;i<=k;++i) {
				count += ncr[(int)(i)] *nine;
				nine *= 9L;
			}
			return count;
		}
		
		long f(int it, int k, int inv, String s) {
			if(it == 20)
				return 1;
			if(inv == 1) {
				return g(20L-it, 3 - k);
			}
			if(k == 3) {
				return 1;
			}
			long ret = 0;
			for(char d='0';d<=s.charAt(it);++d) {
				int kk = k;
				if(d != '0')
					++kk;
				if(kk > 3)
					continue;
				if(d == s.charAt(it)) {
					ret += f(it + 1, kk, 0, s);
				} else {
					ret += f(it + 1, kk, 1, s);
				}
			}
			return ret;
		}
		
	}
	
	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}
	
	public static void main(String[] args) {
        prepareIO(false);
	}
	
	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        
        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }
        
        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }
        
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.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());
        }

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

}