Problem: Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.

Input

The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two natural numbers li and ri (1 ≤ li ≤ ri ≤ 9 ·1018).

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Output

Output should contain t numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from li to ri, inclusively).

Examples

Input

1
1 9


Output

9


Input

1
12 15


Output

2

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Conmtest51_4 {
    static long[][][][][] DP;
    static long[] pow7;
    static long[] pow8;
    static long[] pow9;

    public static long call2(int i, int mask, int flag7, int flag8, int flag9) {
        if (DP[i][mask][flag7][flag8][flag9] != -1)
            return DP[i][mask][flag7][flag8][flag9];
        long res = 0;
        if (i == 1) {
            for (int j = 0; j < 10; j++) {
                if ((mask & 1 << 3) != 0 && j != 5 && j != 0)
                    continue;
                int newflag7 = (int) ((flag7 + ((j * pow7[i-1]) % 7)) % 7);
                int newflag8 = (int) ((flag8 + ((j * pow8[i-1]) % 8)) % 8);
                int newflag9 = (int) ((flag9 + ((j * pow9[i-1]) % 9)) % 9);
                int newmask = mask;
                if (j > 1)
                    newmask = mask | (1 << (j - 2));
                res += call2(i - 1, newmask, newflag7, newflag8, newflag9);
            }
        } else if (i == 0) {
            boolean flag = true;
            if ((mask & (1 << 0)) != 0)
                flag &= flag8 % 2 == 0;
            if ((mask & (1 << 1)) != 0)
                flag &= flag9 % 3 == 0;
            if ((mask & (1 << 2)) != 0)
                flag &= flag8 % 4 == 0;
            if ((mask & (1 << 4)) != 0)
                flag &= flag8 % 2 == 0 && flag9 % 3 == 0;
            if ((mask & (1 << 5)) != 0)
                flag &= flag7 == 0;
            if ((mask & (1 << 6)) != 0)
                flag &= flag8 == 0;
            if ((mask & (1 << 7)) != 0)
                flag &= flag9 == 0;
            return flag ? 1 : 0;
        } else {
            for (int j = 0; j < 10; j++) {
                int newflag7 = (int) ((flag7 + ((j * pow7[i-1]) % 7)) % 7);
                int newflag8 = (int) ((flag8 + ((j * pow8[i-1]) % 8)) % 8);
                int newflag9 = (int) ((flag9 + ((j * pow9[i-1]) % 9)) % 9);
                int newmask = mask;
                if (j > 1)
                    newmask = mask | (1 << (j - 2));
                res += call2(i - 1, newmask, newflag7, newflag8, newflag9);
            }
        }
        return DP[i][mask][flag7][flag8][flag9] = res;
    }
    public static long call1(long num) {
        String a = "" + num;
        long res = 0;
        int mask = 0;
        int flag7 = 0;
        int flag8 = 0;
        int flag9 = 0;
        int nw = a.length() - 1;
        for (int i = 0; i < a.length(); i++) {
            int curr = a.charAt(i) - '0';
            for (int j = 0; j < curr; j++) {
                int newflag7 = (int) ((flag7 + ((j * pow7[nw]) % 7)) % 7);
                int newflag8 = (int) ((flag8 + ((j * pow8[nw]) % 8)) % 8);
                int newflag9 = (int) ((flag9 + ((j * pow9[nw]) % 9)) % 9);
                int newmask = mask;
                if (j > 1)
                    newmask = mask | (1 << (j - 2));
                if(j!=0 && j!=5 && (mask&(1<<3))!=0 && i==a.length()-1)
                    continue;
                res += call2(a.length()-i-1, newmask, newflag7, newflag8, newflag9);
            }
            flag7 = (int) ((flag7 + ((curr * pow7[nw]) % 7)) % 7);
            flag8 = (int) ((flag8 + ((curr * pow8[nw]) % 8)) % 8);
            flag9 = (int) ((flag9 + ((curr * pow9[nw--]) % 9)) % 9);
            if (curr > 1)
                mask = mask | (1 << (curr - 2));
            if(i==a.length()-1){
                boolean flag = true;
                if ((mask & (1 << 0)) != 0)
                    flag &= flag8 % 2 == 0;
                if ((mask & (1 << 1)) != 0)
                    flag &= flag9 % 3 == 0;
                if ((mask & (1 << 2)) != 0)
                    flag &= flag8 % 4 == 0;
                if ((mask & (1 << 4)) != 0)
                    flag &= flag8 % 2 == 0 && flag9 % 3 == 0;
                if ((mask & (1 << 5)) != 0)
                    flag &= flag7 == 0;
                if ((mask & (1 << 6)) != 0)
                    flag &= flag8 == 0;
                if ((mask & (1 << 7)) != 0)
                    flag &= flag9 == 0;
                if((mask&(1<<3))!=0 && !(curr==5 || curr==0))
                    flag = false;
                if(flag)
                res++;
            }
        }
        return res;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(in.readLine());
        DP = new long[19][257][7][8][9];
        for (int i = 0; i < 19; i++) {
            for (int j = 0; j < 257; j++) {
                for (int j2 = 0; j2 < 7; j2++) {
                    for (int k = 0; k < 8; k++) {
                        for (int k2 = 0; k2 < 9; k2++) {
                            DP[i][j][j2][k][k2] = -1;
                        }
                    }
                }
            }
        }
        pow7 = new long[19];
        pow8 = new long[19];
        pow9 = new long[19];
        pow7[0] = pow8[0] = pow9[0] = 1;
        pow7[1] = 3;
        pow8[1] = 2;
        pow9[1] = 1;
        for (int i = 2; i < 19; i++) {
            pow7[i] = (pow7[i - 1] * 3) % 7;
            pow8[i] = (pow8[i - 1] * 2) % 8;
            pow9[i] = (pow9[i - 1] * 1) % 9;
        }
        for (int i = 0; i < t; i++) {
            String[] s = in.readLine().split(" ");
            long st = Long.parseLong(s[0]) - 1;
            long end = Long.parseLong(s[1]);
            long a = call1(end);
            long b = call1(st);
            System.out.println(a - b);
        }
    }
}