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 class FastScanner{
	        	   BufferedReader br;
	        	   StringTokenizer st;
	        	   public FastScanner(InputStream in) {
					// TODO Auto-generated constructor stub
	        		  br=new BufferedReader(new InputStreamReader(in),16384);
	        		  eats("");
				   } 
	        	   public void eats(String s) {
	        		  st=new StringTokenizer(s);
	        		   return ;
	        	   }
	        	   public String nextLine() {
	        		   try {
	        			   return br.readLine();
					} catch (Exception e) {
						// TODO: handle exception
						return null;
					}
	        		   
	        	   }
	        	   public boolean hasNext() {
	        		   while(!st.hasMoreElements()) {
	        			   String s=nextLine();
	        			   if(s==null)return false;
	        			   eats(s);
	        		   }
	        		   return true;
	        	   }
	        	   public String next() {
	        		   hasNext();
	        		   return st.nextToken();
	        	   }
	        	   public int nextInt() {
	        		   return Integer.parseInt(next());
	        	   }
	        	   public long nextLong() {
	        		   return Long.parseLong(next());
	        	   }
	        }
	        static FastScanner cin=new FastScanner(System.in);
	        static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	        static long  dp[][]=new long [25][25];
	        static long  num[]=new long [25];
	        static long dfs(int pos,int sum,boolean limit ) {
	        	//out.println(pos+" "+sum);
	        	if(pos==-1) {
	        		if(sum<=3) {
	        			return 1;
	        		}
	        		else {
	        			return 0;
	        		}
	        	}
	        	if(!limit&&dp[pos][sum]!=-1)return dp[pos][sum];
	        	long ans=0;
	        	int up=(int) (limit?num[pos]:9);
	            for(int i=0;i<=up;i++) {
	            	if(i==0) {
	            		ans+=dfs(pos-1, sum, limit&&num[pos]==i);
	            	}
	            	else {
	            		ans+=dfs(pos-1, sum+1, limit&&num[pos]==i);
	            	}
	            }
	         
	            if(!limit)dp[pos][sum]=ans;
	            return ans;
	        	
	        	
	        	
	        }
	        static long cal(long x) {
	        	int cnt=0;
	        	while(x!=0) {
	        		num[cnt]=x%10;
	        		cnt++;
	        		x/=10;
	        	}
	        	return dfs(cnt-1,0,true);
	        }
	        public static void main(String[] args) {
	        	int T;
	        	T=cin.nextInt();
	        	long l,r;
	            
	        	for(int i=1;i<=T;i++) {
	        		for(int j=0;j<25;j++) {
	        			for(int k=0;k<25;k++) {
	        				dp[j][k]=-1;
	        			}
	        		}
	        		l=cin.nextLong();
	        		r=cin.nextLong();
	        	
	        		
	        		out.println(cal(r)-cal(l-1));
	        		
	        	}
	        	out.flush();
	        	return ;
	        }
}