#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
  fast_ios() {
    cin.tie(nullptr), ios::sync_with_stdio(false),
        cout << fixed << setprecision(20);
  };
} fast_ios_;
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg) std::cout << v << ' ';
  err(args...);
}
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
long long powmod(long long a, long long b) {
  long long res = 1;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
const int N = 2e5 + 10;
int C[25][25];
void init() {
  for (int i = 0; i < 20; i++)
    for (int j = 0; j < i + 1; j++) {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
}
int solve(long long n) {
  if (!n) return 0;
  vector<int> nums;
  while (n) nums.push_back(n % 10), n /= 10;
  int res = 0, last = 0;
  for (int i = nums.size() - 1; i >= 0; --i) {
    int x = nums[i], pos = i + 1;
    for (int j = (i == nums.size() - 1); j < x; ++j) {
      if (j == 0) {
        for (int k = 0; k <= min(pos - 1, 3 - last); ++k) {
          res += C[pos - 1][k] * powmod(9, k);
        }
      } else {
        for (int k = 0; k <= min(pos - 1, 3 - last - 1); ++k) {
          res += C[pos - 1][k] * powmod(9, k);
        }
      }
    }
    if (x) last++;
    if (last > 3) break;
    if (!i && last <= 3) res++;
  }
  for (int i = 1; i < nums.size(); ++i) {
    for (int j = 0; j <= min(i - 1, 2); ++j) {
      res += C[i - 1][j] * powmod(9, j + 1);
    }
  }
  return res;
}
int main() {
  int T;
  cin >> T;
  init();
  while (T--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << '\n';
  }
  return 0;
}

### Prompt

Create a solution in cpp for 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;
struct fast_ios {
  fast_ios() {
    cin.tie(nullptr), ios::sync_with_stdio(false),
        cout << fixed << setprecision(20);
  };
} fast_ios_;
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg) std::cout << v << ' ';
  err(args...);
}
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
long long powmod(long long a, long long b) {
  long long res = 1;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
const int N = 2e5 + 10;
int C[25][25];
void init() {
  for (int i = 0; i < 20; i++)
    for (int j = 0; j < i + 1; j++) {
      if (!j)
        C[i][j] = 1;
      else
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
}
int solve(long long n) {
  if (!n) return 0;
  vector<int> nums;
  while (n) nums.push_back(n % 10), n /= 10;
  int res = 0, last = 0;
  for (int i = nums.size() - 1; i >= 0; --i) {
    int x = nums[i], pos = i + 1;
    for (int j = (i == nums.size() - 1); j < x; ++j) {
      if (j == 0) {
        for (int k = 0; k <= min(pos - 1, 3 - last); ++k) {
          res += C[pos - 1][k] * powmod(9, k);
        }
      } else {
        for (int k = 0; k <= min(pos - 1, 3 - last - 1); ++k) {
          res += C[pos - 1][k] * powmod(9, k);
        }
      }
    }
    if (x) last++;
    if (last > 3) break;
    if (!i && last <= 3) res++;
  }
  for (int i = 1; i < nums.size(); ++i) {
    for (int j = 0; j <= min(i - 1, 2); ++j) {
      res += C[i - 1][j] * powmod(9, j + 1);
    }
  }
  return res;
}
int main() {
  int T;
  cin >> T;
  init();
  while (T--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << '\n';
  }
  return 0;
}

```