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 lot[60] = {1,   1,   2,   3,   4,   5,   6,   7,    8,   9,
                     10,  12,  14,  15,  18,  20,  21,  24,   28,  30,
                     35,  36,  40,  42,  45,  56,  60,  63,   70,  72,
                     84,  90,  105, 120, 126, 140, 168, 180,  210, 252,
                     280, 315, 360, 420, 504, 630, 840, 1260, 2520};
long long lcm[60][20] = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
                         {1, 1, 2, 3, 4, 5, 6, 7, 8, 9},
                         {2, 2, 2, 6, 4, 10, 6, 12, 8, 14},
                         {3, 3, 6, 3, 11, 13, 6, 16, 17, 9},
                         {4, 4, 4, 11, 4, 15, 11, 18, 8, 21},
                         {5, 5, 10, 13, 15, 5, 19, 20, 22, 24},
                         {6, 6, 6, 6, 11, 19, 6, 23, 17, 14},
                         {7, 7, 12, 16, 18, 20, 23, 7, 25, 27},
                         {8, 8, 8, 17, 8, 22, 17, 25, 8, 29},
                         {9, 9, 14, 9, 21, 24, 14, 27, 29, 9},
                         {10, 10, 10, 19, 15, 10, 19, 28, 22, 31},
                         {11, 11, 11, 11, 11, 26, 11, 30, 17, 21},
                         {12, 12, 12, 23, 18, 28, 23, 12, 25, 34},
                         {13, 13, 19, 13, 26, 13, 19, 32, 33, 24},
                         {14, 14, 14, 14, 21, 31, 14, 34, 29, 14},
                         {15, 15, 15, 26, 15, 15, 26, 35, 22, 37},
                         {16, 16, 23, 16, 30, 32, 23, 16, 36, 27},
                         {17, 17, 17, 17, 17, 33, 17, 36, 17, 29},
                         {18, 18, 18, 30, 18, 35, 30, 18, 25, 39},
                         {19, 19, 19, 19, 26, 19, 19, 38, 33, 31},
                         {20, 20, 28, 32, 35, 20, 38, 20, 40, 41},
                         {21, 21, 21, 21, 21, 37, 21, 39, 29, 21},
                         {22, 22, 22, 33, 22, 22, 33, 40, 22, 42},
                         {23, 23, 23, 23, 30, 38, 23, 23, 36, 34},
                         {24, 24, 31, 24, 37, 24, 31, 41, 42, 24},
                         {25, 25, 25, 36, 25, 40, 36, 25, 25, 44},
                         {26, 26, 26, 26, 26, 26, 26, 43, 33, 37},
                         {27, 27, 34, 27, 39, 41, 34, 27, 44, 27},
                         {28, 28, 28, 38, 35, 28, 38, 28, 40, 45},
                         {29, 29, 29, 29, 29, 42, 29, 44, 29, 29},
                         {30, 30, 30, 30, 30, 43, 30, 30, 36, 39},
                         {31, 31, 31, 31, 37, 31, 31, 45, 42, 31},
                         {32, 32, 38, 32, 43, 32, 38, 32, 46, 41},
                         {33, 33, 33, 33, 33, 33, 33, 46, 33, 42},
                         {34, 34, 34, 34, 39, 45, 34, 34, 44, 34},
                         {35, 35, 35, 43, 35, 35, 43, 35, 40, 47},
                         {36, 36, 36, 36, 36, 46, 36, 36, 36, 44},
                         {37, 37, 37, 37, 37, 37, 37, 47, 42, 37},
                         {38, 38, 38, 38, 43, 38, 38, 38, 46, 45},
                         {39, 39, 39, 39, 39, 47, 39, 39, 44, 39},
                         {40, 40, 40, 46, 40, 40, 46, 40, 40, 48},
                         {41, 41, 45, 41, 47, 41, 45, 41, 48, 41},
                         {42, 42, 42, 42, 42, 42, 42, 48, 42, 42},
                         {43, 43, 43, 43, 43, 43, 43, 43, 46, 47},
                         {44, 44, 44, 44, 44, 48, 44, 44, 44, 44},
                         {45, 45, 45, 45, 47, 45, 45, 45, 48, 45},
                         {46, 46, 46, 46, 46, 46, 46, 46, 46, 48},
                         {47, 47, 47, 47, 47, 47, 47, 47, 48, 47},
                         {48, 48, 48, 48, 48, 48, 48, 48, 48, 48}};
long long l, r, dp[20][2530][50];
long long model[20];
long long dfs(long long dep, long long las, long long num, long long flag) {
  if (dep == 0) return las % lot[num] == 0;
  if (flag == 0 && dp[dep][las][num] != -1) return dp[dep][las][num];
  long long maxn = flag ? model[dep] : 9;
  long long sum = 0;
  for (long long i = 0; i <= maxn; i++) {
    sum += dfs(dep - 1, (las * 10 + i) % 2520, lcm[num][i],
               flag && (i == maxn ? 1 : 0));
  }
  if (flag == 0) return dp[dep][las][num] = sum;
  return sum;
}
long long spl(long long n) {
  long long x = 0;
  while (n != 0) {
    model[++x] = n % 10;
    n /= 10;
  }
  return dfs(x, 0, 1, 1);
}
long long t;
int main() {
  cin >> t;
  memset(dp, -1, sizeof(dp));
  while (t--) {
    cin >> l >> r;
    cout << spl(r) - spl(l - 1) << endl;
  }
  return 0;
}