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

public class ClassyNumbers { 
	static long memo[][][][]; 
	static int[] L; 
	static int[] R;  
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		while(T-->0) {
			
			String l=sc.next();
			String r=sc.next();
			
			memo=new long[2][2][4][r.length()+1];
			
			for(int i=0;i<2;i++)
				for(int i1=0;i1<2;i1++)
					for(int i11=0;i11<4;i11++)
						Arrays.fill(memo[i][i1][i11],-1);
			
			
			L=new int[r.length()];
			R=new int[r.length()];
			
			int diff=r.length()-l.length();
			for(int i=0;i<diff;i++) 
				l="0"+l;
			
			for(int i=0;i<r.length();i++)
			{
				L[i]=Integer.parseInt(l.charAt(i)+"");
				R[i]=Integer.parseInt(r.charAt(i)+"");
			}
			
			System.out.println(dp(true,true,0,0));
		}
	}
	
	public static long dp(boolean Upper,boolean Lower, int nonzero,int idx) {
		
		if(idx==R.length && nonzero<=3)
			return 1;
			
		if(nonzero>3||idx==R.length)
			return 0;
		
		if(memo[Upper?1:0][Lower?1:0][nonzero][idx]!=-1)
			return memo[Upper?1:0][Lower?1:0][nonzero][idx];
		
		int sum=0;
		int start=0;
		int end=9;
		
		if(Upper)  end=R[idx];
		
		if(Lower)  start=L[idx];
	
		for(int i=start; i<=end;i++) 
			sum+=dp(Upper&(i==R[idx]),Lower& (i==L[idx]), i==0?nonzero:nonzero+1, idx+1);	
		
		return memo[Upper?1:0][Lower?1:0][nonzero][idx]= sum;
	}
	
	
	
	static class Scanner 
	{
	    StringTokenizer st;
	    BufferedReader br;

	    public Scanner(InputStream s){    br = new BufferedReader(new InputStreamReader(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());}
	    

	}
}