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>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int Lcm[49], cl, id[2521], Gcd[2521][2521];
bool tmp[2521];
long long f[21][49][2521], ten[21];
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int get(int l, int x) {
  int nl;
  if (!x && !l) nl = 0;
  if (x && l) nl = l * x / Gcd[l][x];
  if (!x && l) nl = l;
  if (x && !l) nl = x;
  return nl;
}
int num[21];
long long sum(long long x) {
  int cnt = 0;
  long long tx = x;
  while (x) num[++cnt] = x % 10, x /= 10;
  long long ans = 0;
  int l = 1;
  for (int i = cnt; i; i--) {
    for (int j = 0; j < num[i]; j++) {
      int nl = get(l, j);
      for (int k = 0; k <= cl; k++) {
        int nnl = get(nl, Lcm[k]);
        long long t;
        if (i < cnt)
          t = (tx / ten[i] * ten[i] + ten[i - 1] * j) % 2520;
        else
          t = ten[i - 1] * j % 2520;
        for (int m = 0; m < 2521 - 1; m += nnl) {
          int M = (m - t + 2520) % 2520;
          if (M < 0) continue;
          if (f[i - 1][k][M]) ans += f[i - 1][k][M];
        }
      }
    }
    l = get(l, num[i]);
  }
  if (tx % l == 0) ans++;
  return ans;
}
int main() {
  for (int i = 1; i < 2521; i++)
    for (int j = 1; j < 2521; j++) Gcd[i][j] = gcd(i, j);
  tmp[1] = 1;
  for (int j = 2; j <= 9; j++)
    for (int x = 2521 - 1; x; x--)
      if (tmp[x]) tmp[x * j / Gcd[x][j]] = 1;
  for (int i = 1; i < 2521; i++)
    if (tmp[i]) Lcm[++cl] = i, id[i] = cl;
  ten[0] = 1;
  for (int i = 1; i < 21; i++) ten[i] = ten[i - 1] * 10;
  f[0][0][0] = 1;
  for (int j = 0; j <= 9; j++) f[1][id[j]][j] = 1;
  for (int i = 1; i < 21 - 1; i++)
    for (int k = 0; k <= cl; k++)
      for (int m = 0; m < 2521; m++)
        if (f[i][k][m]) {
          int l = Lcm[k];
          for (int x = 0; x <= 9; x++) {
            int nl = get(l, x);
            f[i + 1][id[nl]][(ten[i] * x + m) % 2520] += f[i][k][m];
          }
        }
  int T = read();
  while (T--) {
    long long l = read(), r = read();
    printf("%I64d\n", sum(r) - sum(l - 1));
  }
  return 0;
}