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 Solution implements Runnable {
    FastScanner sc;
    PrintWriter pw;
    
    final class FastScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        public long nlo() {
            return Long.parseLong(next());
        }
 
        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }
 
        public int ni() {
            return Integer.parseInt(next());
        }
 
        public String nli() {
            String line = "";
            if (st.hasMoreTokens()) line = st.nextToken();
            else try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            while (st.hasMoreTokens()) line += " " + st.nextToken();
            return line;
        }
 
        public double nd() {
            return Double.parseDouble(next());
        }
    }
    public static void main(String[] args) throws Exception
    {
        new Thread(null,new Solution(),"codeforces",1<<28).start();
    }
    public void run()
    {
        sc=new FastScanner();
        pw=new PrintWriter(System.out);
        try{
        solve();}
        catch(Exception e)
        {
            pw.println(e);
        }
        pw.flush();
        pw.close();
    }
    public long gcd(long a,long b)
    {
        return b==0L?a:gcd(b,a%b);
    }
    public long ppow(long a,long b,long mod)
    {
        if(b==0L)
        return 1L;
        long tmp=1;
        while(b>1L)
        {
            if((b&1L)==1)
            tmp*=a;
            a*=a;
            a%=mod;
            tmp%=mod;
            b>>=1;
        }
        return (tmp*a)%mod;
    }
    public long pow(long a,long b)
    {
        if(b==0L)
        return 1L;
        long tmp=1;
        while(b>1L)
        {
            if((b&1L)==1)
            tmp*=a;
            a*=a;
            b>>=1;
        }
        return (tmp*a);
    }
    public  int gcd(int x,int y)
    {
        return y==0?x:gcd(y,x%y);
    }
   
    //////////////////////////////////
    /////////////  LOGIC  ///////////
    ////////////////////////////////
    
    public void solve() throws Exception{
      long[] arr=new long[61];
      arr[1]=9;
      arr[2]=90;
      for(int i=3;i<61;i++){
        arr[i]=9L*nc2(i-1)*(81L);
        arr[i]+=9L*((long)(i-1))*9L;
        arr[i]+=9L;
    }
      int t=sc.ni();
      while(t-->0){
          long x=sc.nlo();
          long y=sc.nlo();
          long ans=cal(y,arr)-cal(x-1L,arr);
          pw.println(ans);
      }
    }
    public long nc2(long n){
        return (n*(n-1L))/2L;
    }
    public int digit(long x){
        int ans=0;
        while(x>0){
            ans++;
            x/=10L;
        }
        return ans;
    }
    public long cal(long x,long[] arr){
        if(x==0)
        return 0;
        int d = digit(x);
        //pw.println(d+"-- "+x);
        long ans=0;
        for(int i=1;i<=(d-1);i++)
        ans+=arr[i];
        long den=(long)Math.pow(10L,d-1),num=x;
        long[] drr=new long[d];
        for(int i=0;i<d;i++){
            drr[i]=num/den;
            num-=(drr[i]*den);
            den/=10L;
        }
        den=0;
       // pw.println(ans);
        for(int i=0;i<d;i++){
            if(drr[i]==0)
            continue; 
            den++;
            long p=drr[i]-1;
            if(i!=0)
            {
                long r=3-den+1;
                if(r>=2&&(d-i-1)>1)
                ans+=nc2(d-i-1)*81;
                if(r>=1&&(d-i-1)>=1)
                ans+=9L*((long)(d-i-1));
            }
            ans++;
            long rem=3-den;
            if(rem>=2 && ((d-i-1)>1))
            ans+=(p*nc2(d-i-1)*81L);
            if(rem>=1 && ((d-i-1)>=1))
            ans+=(p*((long)(d-i-1))*9L);
            ans+=p;
            if(rem==0)
            break;
        }
       // pw.println(x+" "+ans);
        return ans;
    }
}