#include <bits/stdc++.h>
using namespace std;
long long cr(long long n, long long r) {
  if (r > n) return 0;
  if (r == 0) return 1;
  if (r == 1) return n;
  if (r == 2) {
    return (n * (n - 1)) / 2LL;
  }
  if (r == 3) {
    return (n * (n - 1) * (n - 2)) / (6LL);
  }
}
long long fn(string s) {
  s = '0' + s;
  long long ans = 0;
  long long i, j, k;
  long long n = s.size();
  k = 0;
  long long r = 0;
  for (i = 0; i < n; i++) {
    long long digi = (s[i] - '0');
    if (digi == 0) continue;
    for (r = 0; r <= 3; r++) {
      if (r + k <= 3) ans += (cr(n - i - 1, r) * pow(9, r));
      if (digi != 0 && r + k + 1 <= 3)
        ans += (digi - 1) * (cr(n - i - 1, r) * pow(9, r));
    }
    if (digi != 0) k++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    y++;
    long long i;
    string a, b;
    a = to_string(x);
    b = to_string(y);
    long long ans = fn(b) - fn(a);
    cout << ans << endl;
  }
}

### Prompt

Construct a cpp code solution to the problem outlined:

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 cr(long long n, long long r) {
  if (r > n) return 0;
  if (r == 0) return 1;
  if (r == 1) return n;
  if (r == 2) {
    return (n * (n - 1)) / 2LL;
  }
  if (r == 3) {
    return (n * (n - 1) * (n - 2)) / (6LL);
  }
}
long long fn(string s) {
  s = '0' + s;
  long long ans = 0;
  long long i, j, k;
  long long n = s.size();
  k = 0;
  long long r = 0;
  for (i = 0; i < n; i++) {
    long long digi = (s[i] - '0');
    if (digi == 0) continue;
    for (r = 0; r <= 3; r++) {
      if (r + k <= 3) ans += (cr(n - i - 1, r) * pow(9, r));
      if (digi != 0 && r + k + 1 <= 3)
        ans += (digi - 1) * (cr(n - i - 1, r) * pow(9, r));
    }
    if (digi != 0) k++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    y++;
    long long i;
    string a, b;
    a = to_string(x);
    b = to_string(y);
    long long ans = fn(b) - fn(a);
    cout << ans << endl;
  }
}

```