#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
long long int h(long long int cur, int non, long long int l, long long int r) {
  if (cur > r) return 0;
  long long int ans = 0;
  if (cur >= l && cur <= r) ans += 1;
  if (non < 3) {
    for (int i = 1; i <= 9; i++) {
      ans += h(cur * 10 + i, non + 1, l, r);
    }
  }
  if (cur != 0) ans += h(cur * 10, non, l, r);
  return ans;
}
long long int dp[20][4];
long long int gn(long long int z) {
  vector<int> a;
  long long int tmp = z;
  while (tmp > 0) {
    a.push_back(tmp % 10);
    tmp /= 10;
  }
  reverse(a.begin(), a.end());
  int n = a.size();
  long long int ans = 0;
  int non = 0;
  for (int i = 0; i < n; i++) {
    non++;
    if (non > 3) continue;
    int rem = n - i - 1;
    if (i == n - 1) {
      ans += (9 - a[i]);
      break;
    }
    long long int cur = 0;
    for (int j = rem; j >= 1; j--)
      for (int k = 0; k + non < 4; k++) cur += dp[j][k];
    ans += ((9 - a[i]) * cur);
    if (a[i] == 0) non--;
  }
  non = 0;
  for (auto x : a)
    if (x != 0) non++;
  if (non <= 3) ans++;
  return ans;
}
void solve() {
  long long int l, r;
  cin >> l >> r;
  long long int ans = 0;
  dp[0][0] = dp[1][0] = 1;
  dp[1][1] = 9;
  dp[1][2] = dp[1][3] = 0;
  for (int i = 2; i < 20; i++) {
    for (int j = 0; j <= 3; j++) {
      if (i < j)
        dp[i][j] = 0;
      else if (j == 0)
        dp[i][j] = 0;
      else if (j == 1)
        dp[i][j] = 9;
      else if (j == 2)
        dp[i][j] = 81 * (i - 1);
      else if (j == 3)
        dp[i][j] = 9 * 9 * 9 * (i - 1) * (i - 2) / 2;
    }
  }
  int len_l = 0, len_r = 0;
  long long int tmp = l;
  while (tmp > 0) {
    len_l++;
    tmp /= 10;
  }
  tmp = r;
  int non = 0;
  while (tmp > 0) {
    if (tmp % 10 != 0) non++;
    len_r++;
    tmp /= 10;
  }
  ans += gn(l);
  for (int i = len_l + 1; i <= len_r; i++) {
    long long int t = 1;
    for (int j = 1; j < i; j++) t *= 10;
    ans += gn(t);
  }
  ans -= gn(r);
  if (non <= 3) ans++;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}

### Prompt

Please create a solution in Cpp 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;
bool cmp(int a, int b) { return a > b; }
long long int h(long long int cur, int non, long long int l, long long int r) {
  if (cur > r) return 0;
  long long int ans = 0;
  if (cur >= l && cur <= r) ans += 1;
  if (non < 3) {
    for (int i = 1; i <= 9; i++) {
      ans += h(cur * 10 + i, non + 1, l, r);
    }
  }
  if (cur != 0) ans += h(cur * 10, non, l, r);
  return ans;
}
long long int dp[20][4];
long long int gn(long long int z) {
  vector<int> a;
  long long int tmp = z;
  while (tmp > 0) {
    a.push_back(tmp % 10);
    tmp /= 10;
  }
  reverse(a.begin(), a.end());
  int n = a.size();
  long long int ans = 0;
  int non = 0;
  for (int i = 0; i < n; i++) {
    non++;
    if (non > 3) continue;
    int rem = n - i - 1;
    if (i == n - 1) {
      ans += (9 - a[i]);
      break;
    }
    long long int cur = 0;
    for (int j = rem; j >= 1; j--)
      for (int k = 0; k + non < 4; k++) cur += dp[j][k];
    ans += ((9 - a[i]) * cur);
    if (a[i] == 0) non--;
  }
  non = 0;
  for (auto x : a)
    if (x != 0) non++;
  if (non <= 3) ans++;
  return ans;
}
void solve() {
  long long int l, r;
  cin >> l >> r;
  long long int ans = 0;
  dp[0][0] = dp[1][0] = 1;
  dp[1][1] = 9;
  dp[1][2] = dp[1][3] = 0;
  for (int i = 2; i < 20; i++) {
    for (int j = 0; j <= 3; j++) {
      if (i < j)
        dp[i][j] = 0;
      else if (j == 0)
        dp[i][j] = 0;
      else if (j == 1)
        dp[i][j] = 9;
      else if (j == 2)
        dp[i][j] = 81 * (i - 1);
      else if (j == 3)
        dp[i][j] = 9 * 9 * 9 * (i - 1) * (i - 2) / 2;
    }
  }
  int len_l = 0, len_r = 0;
  long long int tmp = l;
  while (tmp > 0) {
    len_l++;
    tmp /= 10;
  }
  tmp = r;
  int non = 0;
  while (tmp > 0) {
    if (tmp % 10 != 0) non++;
    len_r++;
    tmp /= 10;
  }
  ans += gn(l);
  for (int i = len_l + 1; i <= len_r; i++) {
    long long int t = 1;
    for (int j = 1; j < i; j++) t *= 10;
    ans += gn(t);
  }
  ans -= gn(r);
  if (non <= 3) ans++;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}

```