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.*;
import java.math.*;
public class Main
{
    static class Reader 
    { 
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} 
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} 
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} 
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} 
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} 
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} 
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } 
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } 
        public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
    }
    static long cache[][][];
    static long check=0;
    static String r;
    public static long dp(int pos,int nozeros,int less)
    {
        if(pos==r.length())
        {
            if(nozeros<=3&&less==1)
            return 1;
            return 0;
        }
        if(cache[pos][nozeros][less]!=-1)
        return cache[pos][nozeros][less];
        if(less==0)
        {
            long ans=0;
            for(int i=0;i<=r.charAt(pos)-48;i++)
            {
                if(i==0)
                {
                    if(i==r.charAt(pos)-48)
                    ans+=dp(pos+1,nozeros,0);
                    else
                    ans+=dp(pos+1,nozeros,1);
                }
                else
                {
                    if(i==r.charAt(pos)-48)
                    ans+=dp(pos+1,nozeros+1,0);
                    else
                    ans+=dp(pos+1,nozeros+1,1);
                }
            }
            return cache[pos][nozeros][less]=ans; 
        }
        else
        {
            long ans=0;
            for(int i=0;i<=9;i++)
            {
                if(i==0)
                ans+=dp(pos+1,nozeros,1);
                else
                ans+=dp(pos+1,nozeros+1,1);
            }
            return cache[pos][nozeros][less]=ans; 
        }
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        int q=sc.i();
        while(q-->0)
        {
            long ll=sc.l();
            long rr=sc.l();
            rr++;
            r=Long.toString(rr);
            cache=new long[20][20][2];
            for(int i=0;i<20;i++)for(int j=0;j<20;j++)Arrays.fill(cache[i][j],-1);
            long ans1=dp(0,0,0);
            for(int i=0;i<20;i++)for(int j=0;j<20;j++)Arrays.fill(cache[i][j],-1);
            r=Long.toString(ll);
            long ans2=dp(0,0,0);
            out.println(ans1-ans2);
        }
        out.flush();
    }
}