#include <bits/stdc++.h>
using namespace std;
long long L, R, ans, b[10];
int a[22], n;
long long C(int n, int m) {
  if (m > n) return 0;
  long long tmp = 1;
  for (int i = 1; i <= m; i++) tmp *= (n - i + 1);
  for (int i = 1; i <= m; i++) tmp /= i;
  return tmp;
}
void cal(int n, int sum) {
  if (n == 0) {
    if (sum <= 3) ans++;
    return;
  }
  for (int i = 0; i < a[n]; i++) {
    for (int j = 0; j <= 3 - sum - (i != 0); j++) ans += C(n - 1, j) * b[j];
  }
  cal(n - 1, sum + (a[n] != 0));
}
long long solve(long long x) {
  n = 0;
  while (x) {
    a[++n] = x % 10;
    x /= 10;
  }
  ans = 0;
  cal(n, 0);
  return ans;
}
int main() {
  b[0] = 1;
  b[1] = 9;
  b[2] = 81;
  b[3] = 81 * 9;
  int T;
  cin >> T;
  while (T--) {
    cin >> L >> R;
    cout << solve(R) - solve(L - 1) << endl;
  }
  return 0;
}

### Prompt

Generate a Cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long L, R, ans, b[10];
int a[22], n;
long long C(int n, int m) {
  if (m > n) return 0;
  long long tmp = 1;
  for (int i = 1; i <= m; i++) tmp *= (n - i + 1);
  for (int i = 1; i <= m; i++) tmp /= i;
  return tmp;
}
void cal(int n, int sum) {
  if (n == 0) {
    if (sum <= 3) ans++;
    return;
  }
  for (int i = 0; i < a[n]; i++) {
    for (int j = 0; j <= 3 - sum - (i != 0); j++) ans += C(n - 1, j) * b[j];
  }
  cal(n - 1, sum + (a[n] != 0));
}
long long solve(long long x) {
  n = 0;
  while (x) {
    a[++n] = x % 10;
    x /= 10;
  }
  ans = 0;
  cal(n, 0);
  return ans;
}
int main() {
  b[0] = 1;
  b[1] = 9;
  b[2] = 81;
  b[3] = 81 * 9;
  int T;
  cin >> T;
  while (T--) {
    cin >> L >> R;
    cout << solve(R) - solve(L - 1) << endl;
  }
  return 0;
}

```