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;
template <typename T>
void read(T &x) {
  x = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
int Max(int x, int y) { return x > y ? x : y; }
int Min(int x, int y) { return x < y ? x : y; }
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long f[20][50][2530], l, r;
int num[2530], s[20], cnt;
long long dp(int len, int now, int lcm, bool lim) {
  if (len == 0) return now % lcm == 0;
  if (lim && f[len][num[lcm]][now] > -1) return f[len][num[lcm]][now];
  long long ans = 0;
  int lmt = lim ? 9 : s[len];
  for (int i = 0; i <= lmt; ++i)
    ans += dp(len - 1, (now * 10 + i) % 2520, i ? lcm * i / gcd(lcm, i) : lcm,
              lim || (i != lmt));
  if (lim) f[len][num[lcm]][now] = ans;
  return ans;
}
long long slv(long long x) {
  int len = 0;
  while (x) s[++len] = x % 10, x /= 10;
  return dp(len, 0, 1, 0);
}
int main() {
  for (int i = 1; i <= 2520; ++i)
    if (2520 % i == 0) num[i] = ++cnt;
  memset(f, -1, sizeof f);
  int T;
  read(T);
  while (T--) {
    read(l), read(r);
    cout << slv(r) - slv(l - 1) << '\n';
  }
  return 0;
}