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 long dp[][][];
public static int countdigit (long b){
	int res=0;
	while(b>0){
		b/=10;
		res++;
	}
	return res;
}
public static int[] ToDigitArray(long b){
	
	
	int res[]=new int[countdigit(b)];
	for(int i=0;i<res.length;i++){
		res[i]=(int)(b%10);
		b/=10;
	}
   
    return res;
}
public static long solve(int[] b,int idx,int count,int restricted){
	if(idx==-1){
		if (count<=3)
		{
			return 1;
		}else{
			return 0;
		}	
	}
	if(dp[idx][count][restricted]!=-1&&restricted!=1){
		return dp[idx][count][restricted];
	}
	long res=0;
	int digit=((restricted==1)?b[idx]:9);
	for(int i=0;i<=digit;i++){
		int rest=(i==b[idx])? restricted:0;
		if(i==0){
			res+=solve(b, idx-1,count,rest);
		}
		else{
			res+=solve(b,idx-1,count+1,rest);
		}
	}
	if(restricted==0){
		dp[idx][count][restricted]=res;
	}
	
	return	res;
	
}





public static int histogram(int []input){
	Stack <Integer> s=new Stack<Integer>();
	int i=0;
	int area=0;
	int maxarea=-(int)1e9;
	int top;
	for( i=0;i<input.length;){
		if(s.isEmpty()|| input[i]>=input[s.peek()]){
			s.push(i);
			i++;
			continue;
		}else{
			
				top=s.pop();
				if(!s.isEmpty()){
					 area=input[top]*(i-s.peek()-1);
					 maxarea=Math.max(maxarea, area);
				}
				else{
					area=input[top]*i;
					 maxarea=Math.max(maxarea, area);
				}
				
			}
		}
	
	while(!s.isEmpty()){
		top=s.pop();
		if(!s.isEmpty()){
			 area=input[top]*(i-s.peek()-1);
			 maxarea=Math.max(maxarea, area);
		}
		else{
			area=input[top]*i;
			 maxarea=Math.max(maxarea, area);
		}
		
	}
	return maxarea;
}
public static int maxarea(int [][] arr){
	int maxarea=-1;
	int curr[]=new int [arr.length];
	for(int i=0;i<arr.length;i++){
		for(int j=0;j<arr.length;j++){
			if(arr[i][j]==0){
				curr[j]=0;
			}
			else{
			curr[j]+=arr[i][j];
		}}
		 maxarea=Math.max(maxarea, histogram(curr));
	}
	return maxarea;
}


			
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner sc=new Scanner(System.in);
	   int	 t=sc.nextInt();
	   while(t-->0){
		 long a=sc.nextLong();
		 long b=sc.nextLong();
		
		int []l=ToDigitArray(b);
		
		int [] r=ToDigitArray(a-1);
		
			dp=new long[l.length][l.length][2];
			for(int i=0;i<l.length;i++){
				for(int j=0;j<l.length;j++){
					for(int k=0;k<2;k++){
						dp[i][j][k]=-1;}
					
				}
				
			}
			long x=solve(l,l.length-1,0,1);
			
			dp=new long[r.length][r.length][2];
			for(int i=0;i<r.length;i++){
				for(int j=0;j<r.length;j++){
					for(int k=0;k<2;k++){
						
					
						dp[i][j][k]=-1;}
					
				}
			}
			long y=solve(r,r.length-1,0,1);
					System.out.println(x-y);
		 }}


	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}
 
		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 double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}}