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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author heifrank
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class TaskD {
        long[][][] dp = new long[20][50][3005];
        int[] bits = new int[20];
        Map<Integer, Integer> ds = new HashMap<>();
        int cnt = 0;
        final int MOD = 2520;

        int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        void dfs2(int p, int pren) {
            if (p == 0) {
                if (!ds.containsKey(pren)) {
                    ds.put(pren, ++cnt);
                }
                return;
            }
            dfs2(p - 1, pren * p / gcd(pren, p));
            dfs2(p - 1, pren);
        }

        public TaskD() {
            for (int i = 0; i < dp.length; i++)
                for (int j = 0; j < dp[0].length; j++) {
                    Arrays.fill(dp[i][j], -1);
                }
            dfs2(9, 1);
        }

        public long dfs(int p, int lcm, int mod, boolean limit) {
            if (p == -1) {
                return mod % lcm == 0 ? 1 : 0;
            }
            int id = ds.get(lcm);
            if (!limit && dp[p][id][mod] != -1) {
                return dp[p][id][mod];
            }
            long ans = 0;
            int end = limit ? bits[p] : 9;
            for (int i = 0; i <= end; i++) {
                ans += dfs(p - 1, i == 0 ? lcm : lcm * i / gcd(lcm, i), (mod * 10 + i) % MOD, limit && i == end);
            }
            if (!limit) {
                dp[p][id][mod] = ans;
            }
            return ans;
        }

        public long calc(long n) {
            int len = 0;
            while (n > 0) {
                Long t = n % 10;
                bits[len++] = t.intValue();
                n /= 10;
            }
            return dfs(len - 1, 1, 0, true);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong();
            long y = in.nextLong();
            out.println(calc(y) - calc(x - 1));
        }

    }
}