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;
#pragma GCC optimize(2)
int t;
long long l, r;
int v[21];
long long f[2][21][2][504][256];
inline int pre(long long x) {
  int ret = 0;
  while (x) {
    ret++;
    v[ret] = x % 10ll;
    x /= 10ll;
  }
  return ret;
}
inline int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }
inline long long calc(long long x) {
  register int m10[504][10];
  register int sh[10];
  for (register int i = 0; i < 504; i++)
    for (register int j = 0; j <= 9; j++) m10[i][j] = (i * 10 + j) % 504;
  for (register int i = 2; i <= 9; i++) sh[i] = 1 << (i - 2);
  register int d = pre(x);
  memset(f, 0, sizeof(f));
  f[0][d + 1][1][0][0] = 1;
  for (register int i = d + 1; i > 1; i--)
    for (register int j = 0; j <= 1; j++) {
      register int h = (j ? v[i - 1] : 9);
      for (register int m = 0; m < 504; m++)
        for (register int s = 0; s < 256; s++)
          if (f[0][i][j][m][s])
            for (register int p = 0; p <= h; p++)
              f[(i == 2) && (p == 0 || p == 5)][i - 1][j && p == v[i - 1]]
               [m10[m][p]][s | sh[p]] += f[0][i][j][m][s];
    }
  long long ans = 0;
  for (register int i = 0; i < 256; i++) {
    register int g = 1;
    for (register int j = 2; j <= 9; j++)
      if (j != 5)
        if (i & (1 << (j - 2))) g = g * j / gcd(g, j);
    for (register int j = 0; j < 504; j += g) {
      ans += f[1][1][0][j][i] + f[1][1][1][j][i];
      if (((i >> 3) & 1) == 0) ans += f[0][1][0][j][i] + f[0][1][1][j][i];
    }
  }
  return ans;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &l, &r);
    printf("%lld\n", calc(r) - calc(l - 1));
  }
  return 0;
}