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:
//Created by Aminul on 2/7/2019.

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class CF_55D {
    static int a[] = new int[20], n, lcmID[], lcmTable[][];
    static long dp[][][][] = new long[2][20][50][2525];
    static int mark[][][][] = new int[2][20][50][2525];

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        generateLcmID();
        int test = in.nextInt(), tc = 0;
        for (int t = 1; t <= test; t++) {
            long l = in.nextLong(), r = in.nextLong();
            long ans = solve(r, ++tc) - solve(l - 1, ++tc);
            pw.println(ans);
        }
        pw.close();
    }

    static long solve(long num, int tc) {
        makeArray(num);
        return solve(tc, 0, 0, 0, 0);
    }

    static long solve(int tc, int isSmall, int pos, int lcm, int mod) {
        if (pos >= n) {
            if (lcm == 0 || mod % lcm != 0) return 0;
            else return 1;
        }
        int rem = n - pos, lid = lcmID[lcm];
        if (isSmall == 1 && mark[isSmall][rem][lid][mod] > 0) return dp[isSmall][rem][lid][mod];
        if (mark[isSmall][rem][lid][mod] == tc) return dp[isSmall][rem][lid][mod];
        mark[isSmall][rem][lid][mod] = tc;

        long res = 0;
        for (int i = 0; i <= 9; i++) {
            if (isSmall == 0 && a[pos] < i) break;
            res += solve(tc, isSmall | boolToInt(i < a[pos]), pos + 1, lcmTable[lcm][i], ((mod * 10) + i) % 2520);
        }
        return dp[isSmall][rem][lid][mod] = res;
    }

    static int boolToInt(boolean b) {
        return b ? 1 : 0;
    }

    static void makeArray(long num) {
        String s = String.valueOf(num);
        n = s.length();
        for (int i = 0; i < n; i++) {
            a[i] = s.charAt(i) - '0';
        }
    }

    static void generateLcmID() {
        lcmID = new int[2525];
        lcmTable = new int[2525][10];
        int id = 0;
        int n = 10;
        for (int i = 0; i < (1 << n); i++) {
            int LCM = 0;
            for (int j = 0; j < n; j++) {
                if (j > 0 && check(i, j)) {
                    if (LCM == 0) LCM = j;
                    else LCM = lcm(LCM, j);
                }
            }
            if (lcmID[LCM] == 0) {
                lcmID[LCM] = ++id;
            }
            for (int j = 0; j <= 9; j++) {
                lcmTable[LCM][j] = lcm(LCM, j);
            }
        }
    }

    static boolean check(int N, int pos) {
        return (N & (1 << pos)) != 0;
    }

    static int gcd(int p, int q) {
        if (q == 0) return p;
        else return gcd(q, p % q);
    }

    static int lcm(int p, int q) {
        if (p == 0) return q;
        if (q == 0) return p;
        long g = gcd(p, q);
        p /= g;
        return p * q;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}