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 lcm[51], rlc[3000], cnt, lc;
int len, arr[20];
int vis[20][3000][50][2], tim = 0;
long long f[20][3000][50][2];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int Lcm(int a, int b) {
  return max(1, a) * max(1, b) / gcd(max(1, a), max(1, b));
}
long long F(int now, int a, int b, int tp) {
  if (now == len + 1) return a % lcm[b] == 0;
  if (vis[now][a][b][tp] == tim || (tp == 0 && vis[now][a][b][tp] > 0))
    return f[now][a][b][tp];
  vis[now][a][b][tp] = tim;
  long long &ret = f[now][a][b][tp] = 0;
  a = 10 * a % lc;
  for (int i = 0; i <= (tp ? arr[now] : 9); i++)
    ret += F(now + 1, a + i >= lc ? a + i - lc : a + i, rlc[Lcm(lcm[b], i)],
             tp & (arr[now] == i));
  return ret;
}
long long Solve(long long num) {
  ++tim;
  len = 0;
  for (; num;) arr[++len] = num % 10, num /= 10;
  for (int i = 1; i < len - i + 1; i++) swap(arr[i], arr[len - i + 1]);
  for (int i = 19; i >= 0; i--)
    arr[i] = len - 19 + i >= 0 ? arr[len - 19 + i] : 0;
  len = 19;
  return F(1, 0, 1, 1);
}
int main() {
  for (int a = 1; a <= 8; a *= 2)
    for (int b = 1; b <= 9; b *= 3)
      for (int c = 1; c <= 5; c *= 5)
        for (int d = 1; d <= 7; d *= 7) lcm[++cnt] = a * b * c * d;
  sort(lcm + 1, lcm + 1 + cnt);
  for (int i = 1; i <= cnt; i++) rlc[lcm[i]] = i;
  lc = lcm[cnt];
  int T;
  for (scanf("%d", &T); T--;) {
    long long L, R;
    scanf("%I64d%I64d", &L, &R);
    printf("%I64d\n", Solve(R) - Solve(L - 1));
  }
}