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>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 2525;
const int M = 50;
const int p = 2520;
long long read() {
  long long s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x < 10)
    putchar(x + '0');
  else {
    write(x / 10);
    putchar(x % 10 + '0');
  }
}
void print(long long x = -1, char c = '\n') {
  write(x);
  putchar(c);
}
int MOD[114514];
int Mod(register int x) {
  if (~MOD[x]) return MOD[x];
  return MOD[x] = x % p;
}
long long gcd(register long long x, register long long y) {
  return !y ? x : gcd(y, x % y);
}
int LCM[N][N];
inline long long lcm(register long long x, register long long y) {
  if (!x || !y) return x | y;
  if (LCM[x][y]) return LCM[x][y];
  return LCM[x][y] = x / gcd(x, y) * y;
}
int nd[N], d[M], cnt = 0, a[21];
long long dp[21][N][M][2];
long long calc(register long long n) {
  register long long tmp = n;
  register int m = 0;
  while (tmp) {
    a[++m] = tmp % 10;
    tmp /= 10;
  }
  memset(dp, 0, sizeof(dp));
  dp[m + 1][0][1][1] = 1;
  for (register int i = m; i >= 1; i--)
    for (register int j = 0; j < p; j++)
      for (register int k = 1; k <= cnt; k++) {
        if (dp[i + 1][j][k][0])
          for (register int t = 0; t <= 9; t++)
            dp[i][Mod(j * 10 + t)][nd[lcm(d[k], t)]][0] += dp[i + 1][j][k][0];
        if (dp[i + 1][j][k][1]) {
          for (register int t = 0; t < a[i]; t++)
            dp[i][Mod(j * 10 + t)][nd[lcm(d[k], t)]][0] += dp[i + 1][j][k][1];
          dp[i][Mod(j * 10 + a[i])][nd[lcm(d[k], a[i])]][1] +=
              dp[i + 1][j][k][1];
        }
      }
  long long ret = 0;
  for (register int j = 0; j < p; j++)
    for (register int k = 1; k <= cnt; k++)
      if (j % d[k] == 0) ret += dp[1][j][k][0] + dp[1][j][k][1];
  return ret;
}
signed main(int Recall, char *_902_[]) {
  memset(MOD, -1, sizeof(MOD));
  for (int i = 1; i <= p; i++)
    if (p % i == 0) {
      d[++cnt] = i;
      nd[i] = cnt;
    }
  int T = read();
  while (T--) {
    long long l = read(), r = read();
    print(calc(r) - calc(l - 1));
  }
  return 0;
}