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;
long long int p10[20] = {1}, p9[20] = {1};
int pow10(long long int n) {
  int ret = 0;
  while (n) {
    n /= 10;
    ret++;
  }
  return ret;
}
long long int C(long long int n, long long int k) {
  if (k > n) return 0;
  if (k == 0) return 1;
  if (k == 1) return n;
  if (k == 2) return n * (n - 1) / 2;
  if (k == 3) return n * (n - 1) * (n - 2) / 6;
  return 1;
}
long long int Cs(long long int n, long long int k) {
  long long int r = 0;
  for (int lk = 0; lk <= k; lk++) r += C(n, lk) * p9[lk];
  return r;
}
long long int f(long long int n) {
  if (n <= 1000) return n + 1;
  int p = pow10(n);
  long long int ret = 0;
  int c1 = 0;
  for (int lx = p; lx; lx--) {
    n %= p10[lx];
    long long int a = n / p10[lx - 1];
    if (lx >= 2) {
      if (a and c1 < 3) {
        ret += Cs(lx - 1, 3 - c1);
        if (c1 <= 2) ret += (a - 1) * Cs(lx - 1, 2 - c1);
        c1++;
      }
    } else {
      if (c1 < 3) {
        ret += a + 1;
      } else if (c1 == 3) {
        ret++;
      }
    }
  }
  return ret;
}
int main() {
  for (int lx = 1; lx < 20; lx++)
    p10[lx] = p10[lx - 1] * 10, p9[lx] = p9[lx - 1] * 9;
  int q;
  scanf("%d", &q);
  while (q--) {
    long long int a, b;
    scanf("%I64d %I64d", &a, &b);
    printf("%I64d\n", f(b) - f(a - 1));
  }
  return 0;
}