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 CPP):

Solution:
#include <bits/stdc++.h>
int const maxl = 22;
int const maxm = 2520;
long long f[maxl][maxm + 4][50][2];
int a[maxl];
std::vector<int> alcm;
long long plcm[maxm + 4][10];
long long kth[maxm + 4];
long long l, r;
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int lcm(int x, int y) {
  if (!x) return y;
  if (!y) return x;
  return x * y / gcd(x, y);
}
void init() {
  for (int i2 = 0, t2 = 1; i2 < 4; i2++, t2 *= 2)
    for (int i3 = 0, t3 = 1; i3 < 3; i3++, t3 *= 3)
      for (int i5 = 0, t5 = 1; i5 < 2; i5++, t5 *= 5)
        for (int i7 = 0, t7 = 1; i7 < 2; i7++, t7 *= 7)
          alcm.push_back(t2 * t3 * t5 * t7);
  std::sort(alcm.begin(), alcm.end());
  for (int i = 0; i <= maxm; i++)
    for (int j = 0; j < 10; j++) plcm[i][j] = lcm(i, j);
  for (int i = 0; i < (int)alcm.size(); i++) kth[alcm[i]] = i;
}
int get_len(long long x) {
  int ret = 0;
  for (; x; x /= 10) a[ret++] = x % 10;
  return ret;
}
long long calc(long long x) {
  int n = get_len(x);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < maxm; j++)
      for (int k = 0; k < (int)alcm.size(); k++)
        for (int l = 0; l < 2; l++) f[i][j][k][l] = 0;
  f[0][0][0][0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < maxm; j++)
      for (int k = 0; k < (int)alcm.size(); k++)
        for (int l = 0; l < 2; l++) {
          if (!f[i][j][k][l]) continue;
          int up = (l ? 9 : a[n - i - 1]);
          for (int ti = 0; ti <= up; ti++) {
            int last = l || (ti < a[n - i - 1]);
            f[i + 1][(j * 10 + ti) % maxm][kth[plcm[alcm[k]][ti]]][last] +=
                f[i][j][k][l];
          }
        }
  long long ans = 0;
  for (int i = 0; i < maxm; i++)
    for (int k = 0; k < (int)alcm.size(); k++)
      for (int l = 0; l < 2; l++)
        if (!(i % alcm[k])) ans += f[n][i][k][l];
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  init();
  int T;
  std::cin >> T;
  while (T--) {
    std::cin >> l >> r;
    std::cout << calc(r) - calc(l - 1) << '\n';
  }
}