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 qpow(long long a, long long b) {
  long long res = 1, base = a;
  while (b) {
    if (b % 2) res = res * base;
    base = base * base;
    b /= 2;
  }
  return res;
}
long long powmod(long long a, long long b) {
  long long res = 1, base = a;
  while (b) {
    if (b % 2) res = res * base % 1000000007;
    base = base * base % 1000000007;
    b /= 2;
  }
  return res;
}
void scanf(int &__x) {
  __x = 0;
  char __ch = getchar();
  while (__ch == ' ' || __ch == '\n') __ch = getchar();
  while (__ch >= '0' && __ch <= '9')
    __x = __x * 10 + __ch - '0', __ch = getchar();
}
long long gcd(long long _a, long long _b) {
  if (!_b)
    return _a;
  else
    return gcd(_b, _a % _b);
}
const int tt = 2520;
long long dp[20][3000][50];
int x[50], mpp[3000];
int s[50];
int cnt;
void init(void) {
  cnt = 0;
  for (int i = 1; i <= tt; i++)
    if (tt % i == 0) x[++cnt] = i, mpp[i] = cnt;
  memset(dp, -1, sizeof dp);
}
long long dfs(int pos, int sum, int lcm, int limit) {
  if (pos == 0) {
    if (sum % x[lcm] == 0)
      return 1;
    else
      return 0;
  }
  if (dp[pos][sum][lcm] != -1 && !limit) return dp[pos][sum][lcm];
  lcm = x[lcm];
  int b = (limit ? s[pos] : 9);
  long long ans = 0;
  for (int i = 0; i <= b; i++) {
    int nlcm;
    if (!i)
      nlcm = lcm;
    else
      nlcm = lcm / gcd(lcm, i) * i;
    ans += dfs(pos - 1, (sum * 10 + i) % tt, mpp[nlcm], limit && i == b);
  }
  if (!limit) dp[pos][sum][mpp[lcm]] = ans;
  return ans;
}
long long calc(long long t) {
  int size = 0;
  while (t) {
    s[++size] = t % 10;
    t /= 10;
  }
  return dfs(size, 0, 1, 1);
}
int main(void) {
  int _;
  long long a, b;
  init();
  while (scanf("%d", &_) != EOF) {
    while (_--) {
      scanf("%I64d%I64d", &a, &b);
      printf("%I64d\n", calc(b) - calc(a - 1LL));
    }
  }
  return 0;
}