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;
int p[30];
long long dp[20][256][2530];
inline bool judge(int num, int r) {
  for (int cnt = 2; num; num >>= 1, cnt++)
    if ((num & 1) && (r % cnt != 0)) return false;
  return true;
}
void solve() {
  for (register int i = 255; ~i; --i)
    for (register int j = 0; j < 2520; j++) dp[0][i][j] = judge(i, j);
  for (register int x = 1; x <= 18; x++) {
    for (register int i = 255; ~i; i--) {
      for (register int j = 0; j < 2520; j++) {
        dp[x][i][j] = dp[x - 1][i][j] + dp[x - 1][i][(j + p[x - 1]) % 2520] +
                      dp[x - 1][i | (2 < 2 ? 0 : (1 << (2 - 2)))]
                        [(j + 2 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (3 < 2 ? 0 : (1 << (3 - 2)))]
                        [(j + 3 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (4 < 2 ? 0 : (1 << (4 - 2)))]
                        [(j + 4 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (5 < 2 ? 0 : (1 << (5 - 2)))]
                        [(j + 5 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (6 < 2 ? 0 : (1 << (6 - 2)))]
                        [(j + 6 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (7 < 2 ? 0 : (1 << (7 - 2)))]
                        [(j + 7 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (8 < 2 ? 0 : (1 << (8 - 2)))]
                        [(j + 8 * p[x - 1]) % 2520] +
                      dp[x - 1][i | (9 < 2 ? 0 : (1 << (9 - 2)))]
                        [(j + 9 * p[x - 1]) % 2520];
      }
    }
  }
}
long long cal(long long num) {
  int q[30], cnt = 0;
  while (num) {
    q[++cnt] = num % 10;
    num /= 10;
  }
  long long ans = 0;
  int nowp = 0, nowr = 0;
  for (register int i = cnt; i; --i) {
    for (register int j = 0; j < q[i]; j++) {
      ans += dp[i - 1][nowp | (j < 2 ? 0 : (1 << (j - 2)))]
               [(nowr + j * p[i - 1]) % 2520];
    }
    nowp |= (q[i] < 2 ? 0 : (1 << (q[i] - 2)));
    nowr = (nowr + q[i] * p[i - 1]) % 2520;
  }
  ans += dp[0][nowp][nowr];
  return ans;
}
void init() {
  p[0] = 1;
  for (int i = 1; i <= 19; i++) {
    p[i] = 10 * p[i - 1];
    p[i] %= 2520;
  }
}
void query() {
  int T;
  scanf("%d", &T);
  for (int i = 1; i <= T; i++) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    printf("%lld\n", cal(r) - cal(l - 1));
  }
}
int main() {
  init();
  solve();
  query();
  return 0;
}