#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
long long ncr(long long n, long long r) {
  if (r == 0) return 1;
  if (r < 0) return 0;
  long long ans = 1;
  for (long long i = n; i > n - r; i--) ans *= i;
  for (long long i = 1; i <= r; i++) ans /= i;
  return ans;
}
long long solve(long long no) {
  string arr = to_string(no);
  long long len = arr.size();
  long long temp = no;
  if (len <= 3) return no;
  long long ans = 0;
  long long cnt = 3;
  for (long long i = 0; i < len; i++) {
    if (arr[i] != '0') {
      for (long long j = 0; j <= cnt; j++) {
        ans += ncr(len - i - 1, j) * pow(9, j);
      }
      for (long long j = 0; j <= cnt - 1; j++) {
        ans += (arr[i] - '0' - 1) * ncr(len - i - 1, j) * pow(9, j);
      }
      cnt--;
    }
    if (cnt == 0) break;
  }
  return ans;
}
int32_t main() {
  long long t;
  cin >> t;
  for (long long i_i = 0; i_i < t; i_i++) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << "\n";
  }
}

### 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;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
long long ncr(long long n, long long r) {
  if (r == 0) return 1;
  if (r < 0) return 0;
  long long ans = 1;
  for (long long i = n; i > n - r; i--) ans *= i;
  for (long long i = 1; i <= r; i++) ans /= i;
  return ans;
}
long long solve(long long no) {
  string arr = to_string(no);
  long long len = arr.size();
  long long temp = no;
  if (len <= 3) return no;
  long long ans = 0;
  long long cnt = 3;
  for (long long i = 0; i < len; i++) {
    if (arr[i] != '0') {
      for (long long j = 0; j <= cnt; j++) {
        ans += ncr(len - i - 1, j) * pow(9, j);
      }
      for (long long j = 0; j <= cnt - 1; j++) {
        ans += (arr[i] - '0' - 1) * ncr(len - i - 1, j) * pow(9, j);
      }
      cnt--;
    }
    if (cnt == 0) break;
  }
  return ans;
}
int32_t main() {
  long long t;
  cin >> t;
  for (long long i_i = 0; i_i < t; i_i++) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << "\n";
  }
}

```