#include <bits/stdc++.h>
using namespace std;
enum { North, East, South, West };
int mi[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int mj[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long l, r;
string num;
bool memo[20][2][4];
long long dp[20][2][4];
long long solve(int p, int t, int s) {
  if (s > 3) return 0;
  if (p == num.size()) return s <= 3;
  if (memo[p][t][s]) return dp[p][t][s];
  long long &ret = dp[p][t][s] = 0;
  if (t) {
    for (int i = 0; i <= (num[p] - '0'); i++) {
      ret += solve(p + 1, i == (num[p] - '0'), s + (i > 0));
    }
  } else {
    for (int i = 0; i <= 9; i++) {
      ret += solve(p + 1, 0, s + (i > 0));
    }
  }
  memo[p][t][s] = true;
  return ret;
}
long long getValue(long long p) {
  num = to_string(p);
  memset(memo, false, sizeof(memo));
  return solve(0, 1, 0);
}
void solve() { printf("%lld\n", getValue(r) - getValue(l - 1)); }
using namespace std::chrono;
class timecheck {
 public:
  high_resolution_clock::time_point t1, t2;
  void start() { t1 = high_resolution_clock::now(); }
  void end() {
    t2 = high_resolution_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
    cout << "Time: " << time_span.count() << "s" << endl;
  }
};
template <class num>
inline void rd(num &x) {
  char c;
  while (isspace(c = getchar()))
    ;
  bool neg = false;
  if (!isdigit(c))
    neg = (c == '-'), x = 0;
  else
    x = c - '0';
  while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
  if (neg) x = -x;
}
int main() {
  int tt;
  rd(tt);
  while (tt--) {
    rd(l), rd(r);
    solve();
  }
  return 0;
}

### Prompt

Your challenge is to write 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;
enum { North, East, South, West };
int mi[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int mj[] = {0, 1, 0, -1, 1, 1, -1, -1};
long long l, r;
string num;
bool memo[20][2][4];
long long dp[20][2][4];
long long solve(int p, int t, int s) {
  if (s > 3) return 0;
  if (p == num.size()) return s <= 3;
  if (memo[p][t][s]) return dp[p][t][s];
  long long &ret = dp[p][t][s] = 0;
  if (t) {
    for (int i = 0; i <= (num[p] - '0'); i++) {
      ret += solve(p + 1, i == (num[p] - '0'), s + (i > 0));
    }
  } else {
    for (int i = 0; i <= 9; i++) {
      ret += solve(p + 1, 0, s + (i > 0));
    }
  }
  memo[p][t][s] = true;
  return ret;
}
long long getValue(long long p) {
  num = to_string(p);
  memset(memo, false, sizeof(memo));
  return solve(0, 1, 0);
}
void solve() { printf("%lld\n", getValue(r) - getValue(l - 1)); }
using namespace std::chrono;
class timecheck {
 public:
  high_resolution_clock::time_point t1, t2;
  void start() { t1 = high_resolution_clock::now(); }
  void end() {
    t2 = high_resolution_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
    cout << "Time: " << time_span.count() << "s" << endl;
  }
};
template <class num>
inline void rd(num &x) {
  char c;
  while (isspace(c = getchar()))
    ;
  bool neg = false;
  if (!isdigit(c))
    neg = (c == '-'), x = 0;
  else
    x = c - '0';
  while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
  if (neg) x = -x;
}
int main() {
  int tt;
  rd(tt);
  while (tt--) {
    rd(l), rd(r);
    solve();
  }
  return 0;
}

```