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.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PandaScanner in = new PandaScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		D solver = new D();
		solver.solve(1, in, out);
		out.close();
	}
}

class D {
    final int MAX = 2520;
    long[][][] memo = new long[19][48][MAX];
    int[] idx = new int[MAX + 1];
    int[] digit = new int[19];
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {

        for (int i = 0; i < 19; i++) {
            for (int j = 0; j < 48; j++) {
                Arrays.fill(memo[i][j], -1);
            }
        }
        idx[0] = -1;
        for (int i = 1; i < MAX + 1; i++) {
            idx[i] = idx[i - 1] + (MAX % i == 0 ? 1 : 0);
        }

        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            long l = in.nextLong();
            long r = in.nextLong();
            out.println(getBeautiful(r) - getBeautiful(l - 1));
        }
    }

    public long getBeautiful(long x) {
        int length = 0;
        for (; x > 0; length++) {
            digit[length] = (int) (x % 10);
            x /= 10;
        }
        return recurse(length - 1, 1, 0, false);
    }

    public long recurse(int pow, int lcm, int mod, boolean under) {
        if (pow == -1) {
            return mod % lcm == 0 ? 1 : 0;
        }
        if (under && memo[pow][idx[lcm]][mod] > -1) {
            return memo[pow][idx[lcm]][mod];
        }
        int limit = under ? 9 : digit[pow];
        long res = 0;
        for (int i = 0; i <= limit; i++) {
            res += recurse(pow - 1, i < 2 ? lcm : (i * lcm / gcd(i, lcm)), (mod * 10 + i) % MAX, under || i < limit);
        }
        return under ? memo[pow][idx[lcm]][mod] = res : res;
    }

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

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }