#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][2];
long long int classy(string &z, int ind, int non, int all) {
  if (non > 3) return 0;
  if (ind == z.size()) return 1LL;
  long long int ans = 0;
  if (dp[ind][non][all] != -1) return dp[ind][non][all];
  if (!all) {
    for (int i = 0; i <= 9; i++) {
      if (i == 0)
        ans += classy(z, ind + 1, non, 0);
      else
        ans += classy(z, ind + 1, non + 1, 0);
    }
  } else {
    int m = z[ind] - '0';
    for (int i = 0; i <= m; i++) {
      if (i == 0)
        ans += classy(z, ind + 1, non, i == m ? 1 : 0);
      else
        ans += classy(z, ind + 1, non + 1, i == m ? 1 : 0);
    }
  }
  dp[ind][non][all] = ans;
  return ans;
}
void solve() {
  memset(dp, -1LL, sizeof(dp));
  string l, r;
  cin >> l >> r;
  long long int ans = classy(r, 0, 0, 1);
  memset(dp, -1LL, sizeof(dp));
  ans -= classy(l, 0, 0, 1);
  int cnt = 0;
  for (int i = 0; i < l.size(); i++)
    if (l[i] != '0') cnt++;
  if (cnt <= 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

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;
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][2];
long long int classy(string &z, int ind, int non, int all) {
  if (non > 3) return 0;
  if (ind == z.size()) return 1LL;
  long long int ans = 0;
  if (dp[ind][non][all] != -1) return dp[ind][non][all];
  if (!all) {
    for (int i = 0; i <= 9; i++) {
      if (i == 0)
        ans += classy(z, ind + 1, non, 0);
      else
        ans += classy(z, ind + 1, non + 1, 0);
    }
  } else {
    int m = z[ind] - '0';
    for (int i = 0; i <= m; i++) {
      if (i == 0)
        ans += classy(z, ind + 1, non, i == m ? 1 : 0);
      else
        ans += classy(z, ind + 1, non + 1, i == m ? 1 : 0);
    }
  }
  dp[ind][non][all] = ans;
  return ans;
}
void solve() {
  memset(dp, -1LL, sizeof(dp));
  string l, r;
  cin >> l >> r;
  long long int ans = classy(r, 0, 0, 1);
  memset(dp, -1LL, sizeof(dp));
  ans -= classy(l, 0, 0, 1);
  int cnt = 0;
  for (int i = 0; i < l.size(); i++)
    if (l[i] != '0') cnt++;
  if (cnt <= 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;
}

```