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 gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int a[20];
long long dp[20][2520][50];
map<int, int> mp, mp_;
long long dfs(int pos, long long sum, int sum_, bool limit) {
  if (pos == -1) {
    if (mp_[sum_] != 0)
      if (sum % mp_[sum_] == 0) return 1;
    return 0;
  }
  if (!limit && dp[pos][sum][sum_] != -1) return dp[pos][sum][sum_];
  int up = limit ? a[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; ++i) {
    if (i != 0 && i != 1) {
      if (mp_[sum_] % i == 0)
        ans += dfs(pos - 1, (sum * 10 + i) % 2520, sum_, limit && i == a[pos]);
      else
        ans += dfs(pos - 1, (sum * 10 + i) % 2520,
                   mp[mp_[sum_] * i / gcd(mp_[sum_], i)], limit && i == a[pos]);
    } else
      ans += dfs(pos - 1, (sum * 10 + i) % 2520, sum_, limit && i == a[pos]);
  }
  if (!limit) dp[pos][sum % 2520][sum_] = ans;
  return ans;
}
long long solve(long long x) {
  int pos = 0;
  while (x) {
    a[pos++] = x % 10;
    x /= 10;
  }
  return dfs(pos - 1, 0, 1, true);
}
int cal2(int a, int b) {
  int res = 1;
  for (int i = 1; i <= b; ++i) res *= a;
  return res;
}
int cal(int i, int j, int k, int l) {
  int res = 1;
  res = res * cal2(2, i);
  res = res * cal2(3, j);
  res = res * cal2(5, k);
  res = res * cal2(7, l);
  return res;
}
int main() {
  long long le, ri;
  int cnt = 0;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int l = 0; l < 2; ++l) {
        for (int k = 0; k < 2; ++k) {
          int tmp = cal(i, j, k, l);
          mp[tmp] = ++cnt, mp_[cnt] = tmp;
        }
      }
    }
  }
  memset(dp, -1, sizeof(dp));
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &le, &ri);
    printf("%lld\n", solve(ri) - solve(le - 1));
  }
  return 0;
}