#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
long long t, L, R, dp[20][4];
long long solve(long long num, int cur, int cnt, long long m) {
  if (cur == 0) return 1;
  long long retval = 0;
  long long tmp = num / m;
  if (tmp) {
    for (int i = 0; i <= cnt; i++) retval += dp[cur - 1][i];
    for (int i = 0; i < cnt; i++) retval += (tmp - 1) * dp[cur - 1][i];
  }
  if (cnt - (tmp ? 1 : 0) >= 0)
    retval += solve(num % m, cur - 1, cnt - (tmp ? 1 : 0), m / 10);
  return retval;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  dp[0][0] = 1;
  dp[1][0] = 1;
  dp[1][1] = 9;
  for (int i = 2; i <= 18; i++) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][0] * 9 + dp[i - 1][1];
    dp[i][2] = dp[i - 1][1] * 9 + dp[i - 1][2];
    dp[i][3] = dp[i - 1][2] * 9 + dp[i - 1][3];
  }
  cin >> t;
  while (t--) {
    cin >> L >> R;
    R = solve(R, 19, 3, 1e18);
    L = solve(L - 1, 19, 3, 1e18);
    cout << R - L << "\n";
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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;
const long long MOD = (long long)1e9 + 7;
long long t, L, R, dp[20][4];
long long solve(long long num, int cur, int cnt, long long m) {
  if (cur == 0) return 1;
  long long retval = 0;
  long long tmp = num / m;
  if (tmp) {
    for (int i = 0; i <= cnt; i++) retval += dp[cur - 1][i];
    for (int i = 0; i < cnt; i++) retval += (tmp - 1) * dp[cur - 1][i];
  }
  if (cnt - (tmp ? 1 : 0) >= 0)
    retval += solve(num % m, cur - 1, cnt - (tmp ? 1 : 0), m / 10);
  return retval;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  dp[0][0] = 1;
  dp[1][0] = 1;
  dp[1][1] = 9;
  for (int i = 2; i <= 18; i++) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][0] * 9 + dp[i - 1][1];
    dp[i][2] = dp[i - 1][1] * 9 + dp[i - 1][2];
    dp[i][3] = dp[i - 1][2] * 9 + dp[i - 1][3];
  }
  cin >> t;
  while (t--) {
    cin >> L >> R;
    R = solve(R, 19, 3, 1e18);
    L = solve(L - 1, 19, 3, 1e18);
    cout << R - L << "\n";
  }
  return 0;
}

```