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.util.*;
import java.io.*;
public class B{

	static int n;
	static char[]X;
	static long [][][]memo;
	static long dp(int idx,int less,int nz)
	{
		if(nz>3)
			return 0;
		if(idx==n)
			return 1;
		if(memo[less][nz][idx]!=-1)
			return memo[less][nz][idx];
		long ans=0;
		int x=X[idx]-'0';
		
		// = x
		int newZ=x==0?nz:nz+1;
		
		ans=ans+dp(idx+1,less,newZ);
		// <x & >=1
		if(x>1)
			ans=ans+(x-1)*dp(idx+1,1,nz+1);
		//>x
		if(less==1 )
		{
			ans=ans+(9-x)*dp(idx+1,1,nz+1);
		}
		if(x!=0)
			ans=ans+dp(idx+1,0<x?1:less,nz);
		return memo[less][nz][idx]=ans;
			
	}
	public static void main(String[] args) throws IOException 
	{
		
		Scanner sc=new Scanner(System.in);
		PrintWriter  out=new PrintWriter(System.out);
		int tc=sc.nextInt();
		while(tc-->0)
		{
			long l=sc.nextLong()-1;
			X=(l+"").toCharArray();
			
			n=X.length;
			long ans=-1;
			 memo=new long [2][4][n+1];
			 for(long [][]aa:memo)
				 for(long []a:aa)
					 Arrays.fill(a, -1);
			if(l!=0)
			 ans=-dp(0,0,0);
			
			long r=sc.nextLong();
			X=(r+"").toCharArray();
			
			n=X.length;
			 memo=new long [2][4][n+1];
			 for(long [][]aa:memo)
				 for(long []a:aa)
					 Arrays.fill(a, -1);
			ans+=dp(0,0,0);
			
			out.println(ans);
		}
			
		
		
		
		out.close();
	
	}
	
	
	
	static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public Scanner(FileReader s) {
            br = new BufferedReader(s);
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
        public boolean ready() throws IOException {return br.ready();}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
       
    }

}