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 L, R, TT, A[20], N;
long long ans1, ans2;
long long zhs[20][5];
long long ksm(long long n, long long k) {
  long long t = n;
  long long re = 1;
  while (k) {
    if (k & 1) {
      re *= t;
    }
    t *= t;
    k >>= 1;
  }
  return re;
}
long long dfs(long long u, long long cnt, long long lim) {
  if (u > N) return 1;
  long long re = 0;
  if (!lim) {
    if (cnt == 0)
      re = 0;
    else
      re = 1;
    for (int i = min(3 - cnt, N - u + 1); i >= 1; --i)
      re += zhs[N - u + 1][i] * ksm(9, i);
    return re;
  }
  for (int i = 0; i <= A[u]; ++i) {
    if (i == 0)
      re += dfs(u + 1, cnt, 0 == A[u] && lim);
    else {
      if (cnt == 3) continue;
      re += dfs(u + 1, cnt + 1, i == A[u] && lim);
    }
  }
  return re;
}
int main() {
  scanf("%I64d", &TT);
  for (int i = 1; i <= 20; ++i) {
    zhs[i][1] = i;
    zhs[i][2] = (i - 1) * i / 2;
    zhs[i][3] = (i - 2) * (i - 1) * i / 3 / 2;
  }
  while (TT--) {
    ans1 = ans2 = 0;
    scanf("%I64d%I64d", &L, &R);
    --L;
    if (L < 1000)
      ans1 = L;
    else {
      for (N = 1; L; ++N) {
        A[N] = L % 10;
        L /= 10;
      }
      for (int i = 1; i <= N; ++i) {
        if (i >= N - i) break;
        swap(A[i], A[N - i]);
      }
      --N;
      ans1 = dfs(1, 0, 1);
    }
    if (R < 1000)
      ans2 = R;
    else {
      for (N = 1; R; ++N) {
        A[N] = R % 10;
        R /= 10;
      }
      for (int i = 1; i <= N; ++i) {
        if (i >= N - i) break;
        swap(A[i], A[N - i]);
      }
      --N;
      ans2 = dfs(1, 0, 1);
    }
    printf("%I64d\n", ans2 - ans1);
  }
}