#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
vector<int> lim;
long long f[21][2][4];
long long count(long long x) {
  lim.clear();
  for (int i = (0); i <= (19); i++) {
    lim.push_back(x % 10);
    x /= 10;
  }
  reverse(lim.begin(), lim.end());
  for (int i = (0); i <= (20); i++)
    for (int b = (0); b <= (1); b++)
      for (int z = (0); z <= (3); z++) f[i][b][z] = 0;
  f[0][0][0] = 1;
  for (int i = (0); i < (20); i++)
    for (int b = (0); b <= (1); b++)
      for (int z = (0); z <= (3); z++)
        if (f[i][b][z]) {
          f[i + 1][(b) || lim[i]][z] += f[i][b][z];
          if (z != 3) {
            if (b)
              f[i + 1][b][z + 1] += f[i][b][z] * 9;
            else if (lim[i]) {
              f[i + 1][1][z + 1] += f[i][b][z] * (lim[i] - 1);
              f[i + 1][b][z + 1] += f[i][b][z];
            }
          }
        }
  long long res = 0;
  for (int b = (0); b <= (1); b++)
    for (int z = (0); z <= (3); z++) res += f[20][b][z];
  return res;
}
void solve() {
  long long l, r;
  read(l);
  read(r);
  writeln(count(r) - count(l - 1));
}
int main() {
  int t;
  read(t);
  while (t--) solve();
}

### 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;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
vector<int> lim;
long long f[21][2][4];
long long count(long long x) {
  lim.clear();
  for (int i = (0); i <= (19); i++) {
    lim.push_back(x % 10);
    x /= 10;
  }
  reverse(lim.begin(), lim.end());
  for (int i = (0); i <= (20); i++)
    for (int b = (0); b <= (1); b++)
      for (int z = (0); z <= (3); z++) f[i][b][z] = 0;
  f[0][0][0] = 1;
  for (int i = (0); i < (20); i++)
    for (int b = (0); b <= (1); b++)
      for (int z = (0); z <= (3); z++)
        if (f[i][b][z]) {
          f[i + 1][(b) || lim[i]][z] += f[i][b][z];
          if (z != 3) {
            if (b)
              f[i + 1][b][z + 1] += f[i][b][z] * 9;
            else if (lim[i]) {
              f[i + 1][1][z + 1] += f[i][b][z] * (lim[i] - 1);
              f[i + 1][b][z + 1] += f[i][b][z];
            }
          }
        }
  long long res = 0;
  for (int b = (0); b <= (1); b++)
    for (int z = (0); z <= (3); z++) res += f[20][b][z];
  return res;
}
void solve() {
  long long l, r;
  read(l);
  read(r);
  writeln(count(r) - count(l - 1));
}
int main() {
  int t;
  read(t);
  while (t--) solve();
}

```