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:
/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*; 
import java.lang.*;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static long mod=(long)1e9+7;
    static long mod1=998244353;
    static boolean sieve[];
    static ArrayList<Integer> primes;
    static ArrayList<Long> factorial;
    static HashSet<Integer> graph[];
/****************************************Solutions Begins***************************************************/
    static ArrayList<Long> num;
    static long dp[][][];
    static int size=0;
    static long helper(int pos,int small,int no){
        if(no>3){
            return 0;
        }
        if(pos==size){
            return 1;
        }
        if(dp[pos][small][no]!=-1){
            return dp[pos][small][no];
        }
        long ans=0;
        for(int i=0;i<=9;i++){
            if(small==1||i<num.get(pos)){
               //out.println(num.get(pos)+" "+small+" "+pos+" hi");
                if(i!=0)
                ans+=helper(pos+1,1,no+1);
                else
                ans+=helper(pos+1,1,no);                
            }
            else if(small==0&&i==num.get(pos)){
                if(i!=0)
                ans+=helper(pos+1,0,no+1);
                else
                ans+=helper(pos+1,0,no);
            }
        }
        dp[pos][small][no]=ans;
        return ans;
    }
    static long fn(long n){
        num=new ArrayList<>();
        long n1=n;
        while(n1!=0){
            long k=n1%10;
            num.add(k);
           // out.println(n1);
            n1/=10;
        }
        Collections.reverse(num);
       // debug(num);
        dp=new long [20][2][4];
        long ans=0;
        long prev=0;

        for(int j=1;j<=num.size();j++){
            size=j;
            for(long arr[][]:dp){
                for(long arr1[]:arr){
                    Arrays.fill(arr1,-1);
                }
            }
            long ans1=0;
            for(int i=1;i<=9;i++){
                if(j<num.size()||i<num.get(0)){
                    ans1+=helper(1,1,1);
                }
                else if(i==num.get(0)){
                    ans1+=helper(1,0,1);
                }
            }
            
            ans+=ans1;
          //  if(ans<prev){out.println("BUGGGGG");}
         // out.println(ans1);
            prev=ans;
        }
        return ans;
        //return 0;
    }
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        //int t=Integer.parseInt(st[0]);
        long t=Long.parseLong(st[0]);

        //long t1=Long.parseLong(st[1]);

       // out.println(fn(t1));
       for(int i1=0;i1<t;i1++){
            st=br.readLine().split(" ");
            long l=Long.parseLong(st[0]);
            long r=Long.parseLong(st[1]);
            long ans=fn(r)-fn(l-1);
           // out.println(fn(l-1)+" "+fn(r));
            out.println(ans);
        }
/****************************************Solutions Ends*****************************************************/
        out.flush();
        out.close();
    }
/****************************************Template Begins***************************************************/
/***************************************Precision Printing**********************************************/
    static void printPrecision(double d){
        DecimalFormat ft = new DecimalFormat("0.000000"); 
        out.println(ft.format(d));
    }
/******************************************Graph***********************************************************/
  /*  static void Makegraph(int n){
        graph=new HashSet[n];
        for(int i=0;i<n;i++){
            graph[i]=new HashSet<>();
        }
    }*/
    static void addEdge(int a,int b){
        graph[a].add(b);
        graph[b].add(a);
    }    
/*******************************************************TRIPLET********************************************/
    static class tripletComparator implements Comparator<triplet>{
        public int compare(triplet p1,triplet p2){
            if(p1.u<p2.u){
                return 1;
            }
            else if(p1.u>p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class triplet{
        int u;
        int v;
        int i;
        public triplet(int u,int v,int i){
            this.u=u;
            this.v=v;
            this.i=i;
        }
        public String toString() {
            return "[u=" + u + ", v=" + v + ", i="+i+"]";
        }
    }
/*********************************************PAIR*************************************************/
    static class PairComp implements Comparator<Pair>{
        public int compare(Pair p1,Pair p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
    static class Pair implements Comparable<Pair> {
        int u;
        int v;
        int index=-1;
        public Pair(int u, int v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/*******************************************LONG PAIR******************************************/
    static class PairCompL implements Comparator<Pairl>{
        public int compare(Pairl p1,Pairl p2){
            if(p1.u>p2.u){
                return 1;
            }
            else if(p1.u<p2.u){
                return -1;
            }
            else{
                return 0;
            }
        }
    }
static class Pairl implements Comparable<Pair> {
        long u;
        long v;
        int index=-1;
        public Pairl(long u, long v) {
            this.u = u;
            this.v = v;
        }
 
        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return 31 * hu + hv;
        }
 
        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }
 
        public int compareTo(Pair other) {
            if(index!=other.index)
                return Long.compare(index, other.index);
            return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
        }
 
        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }
    }
/*****************************************DEBUG***********************************************************/
    public static void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
/*****************************************NUMBER THEORY***********************************************/

/************************************MODULAR EXPONENTIATION************************************/
    static long modulo(long a,long b,long c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return  x%c;
    }
/*********************************************GCD*****************************/
    static long gcd(long x, long y)
    {
        if(x==0)
            return y;
        if(y==0)
            return x;
        long r=0, a, b;
        a = (x > y) ? x : y; // a is greater number
        b = (x < y) ? x : y; // b is smaller number
        r = b;
        while(a % b != 0)
        {
            r = a % b;
            a = b;
            b = r;
        }
        return r;
    }
/*******************************************SIEVE*********************************/
    static void sieveMake(int n){
        sieve=new boolean[n];
        Arrays.fill(sieve,true);
        sieve[0]=false;
        sieve[1]=false;
        for(int i=2;i*i<n;i++){
            if(sieve[i]){
                for(int j=i*i;j<n;j+=i){
                    sieve[j]=false;
                }
            }
        }
        primes=new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            if(sieve[i]){
                primes.add(i);
            }
        }        
    }
/***************************************FACTORIAL*********************************************************/
    static void fact(int n){
        factorial=new ArrayList<>();
        factorial.add((long)1);
        for(int i=1;i<=n;i++){
            factorial.add((factorial.get(i-1)*i)%mod);
        }
    }
/*******************************************ncr*********************************************************/
    static long ncr(int n,int k){
        long aa=modulo(factorial.get(n-k),mod-2,mod);
        long bb=modulo(factorial.get(k),mod-2,mod);
        long cc=factorial.get(n);
        long ans=(aa*cc)%mod;
        ans=(ans*bb)%mod;
        return ans;
    }
/***************************************STRING REVERSE****************************************************/
    static String reverse(String str){
        char r[]=new char[str.length()];
        int j=0;
        for(int i=str.length()-1;i>=0;i--){
            r[j]=str.charAt(i);
            j++;
        }
        return new String(r);
    }
}
/*******************************************************End***********************************************************/