Problem: Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.

You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase.

Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001


Output

1000
1
0
2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int T;
long long L, R;
long long mul[25];
long long f[25][5], g[25][5];
long long get(int digits) {
  if (digits <= 3) return mul[digits] - 1;
  long long ret = (1ll * digits * (digits - 1) * (digits - 2) / 6) * 729 +
                  (1ll * digits * (digits - 1) / 2) * 81 + 1ll * digits * 9;
  return ret;
}
long long solve(long long x) {
  if (x == 0) return 0;
  string str = "";
  long long tmp = x;
  while (tmp) {
    str += (char)(tmp % 10 + '0');
    tmp /= 10;
  }
  reverse(str.begin(), str.end());
  long long a = str.size();
  if (a <= 3) return x;
  int cnt = 0;
  for (int i = 0; i < a; i++)
    if (str[i] != '0') cnt++;
  long long t1 = get(a - 1);
  memset(f, 0, sizeof f);
  memset(g, 0, sizeof g);
  g[0][1] = 1;
  f[0][1] = str[0] - '1';
  for (int i = 0; i < a; i++)
    for (int j = 1; j <= min(3, i + 1); j++) {
      if (g[i][j]) {
        for (int k = 0; k < str[i + 1] - '0'; k++)
          f[i + 1][(k == 0) ? j : j + 1] += g[i][j];
        g[i + 1][str[i + 1] == '0' ? j : j + 1] += g[i][j];
      }
      if (f[i][j]) {
        for (int k = 0; k < 10; k++) f[i + 1][(k == 0) ? j : j + 1] += f[i][j];
      }
    }
  long long t2 = 0;
  for (int i = 1; i <= 3; i++) t2 += f[a - 1][i] + g[a - 1][i];
  return t1 + t2;
}
int main() {
  mul[0] = 1;
  for (int i = 1; i <= 18; i++) mul[i] = mul[i - 1] * 10;
  cin >> T;
  while (T--) {
    cin >> L >> R;
    cout << solve(R) - solve(L - 1) << endl;
  }
  return 0;
}