#include <bits/stdc++.h>
using namespace std;
const int mod = (1e9) + 7;
const double eps = 1e-6;
const int siz = 5e5 + 5, siz2 = 1049659, siz3 = 5032108;
int t;
long long l, r;
string ls, rs;
int lsz, rsz;
long long dpcomb[21][5][2][2];
long long dp1[21][5][2];
long long dpfree[21][5];
long long solvecomb(int i, int nonzero, int free1, int free2) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == lsz) {
    return 1;
  }
  if (dpcomb[i][nonzero][free1][free2] != -1) {
    return dpcomb[i][nonzero][free1][free2];
  }
  int digl = ls[i] - '0', digr = rs[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free1 == 0 && j < digl) {
      continue;
    }
    if (free2 == 0 && j > digr) {
      continue;
    }
    sum += solvecomb(i + 1, nonzero + (j != 0), free1 || (j > digl),
                     free2 || (j < digr));
  }
  return dpcomb[i][nonzero][free1][free2] = sum;
}
long long solvel(int i, int nonzero, int free1) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == lsz) {
    return 1;
  }
  if (dp1[i][nonzero][free1] != -1) {
    return dp1[i][nonzero][free1];
  }
  int digl = ls[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free1 == 0 && j < digl) {
      continue;
    }
    sum += solvel(i + 1, nonzero + (j != 0), free1 || (j > digl));
  }
  return dp1[i][nonzero][free1] = sum;
}
long long solver(int i, int nonzero, int free2) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == rsz) {
    return 1;
  }
  if (dp1[i][nonzero][free2] != -1) {
    return dp1[i][nonzero][free2];
  }
  int digr = rs[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free2 == 0 && j > digr) {
      continue;
    }
    sum += solver(i + 1, nonzero + (j != 0), free2 || (j < digr));
  }
  return dp1[i][nonzero][free2] = sum;
}
long long solvefree(int i, int nonzero, int n) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == n) {
    return 1;
  }
  if (dpfree[i][nonzero] != -1) {
    return dpfree[i][nonzero];
  }
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    sum += solvefree(i + 1, nonzero + (j != 0), n);
  }
  return dpfree[i][nonzero] = sum;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%I64d%I64d", &l, &r);
    ls = to_string(l);
    rs = to_string(r);
    lsz = ls.size();
    rsz = rs.size();
    if (lsz == rsz) {
      memset(dpcomb, -1, sizeof dpcomb);
      printf("%I64d\n", solvecomb(0, 0, 0, 0));
    } else {
      long long ans = 0;
      memset(dp1, -1, sizeof dp1);
      ans += solvel(0, 0, 0);
      memset(dp1, -1, sizeof dp1);
      ans += solver(0, 0, 0);
      for (int i = lsz + 1; i < rsz; i++) {
        memset(dpfree, -1, sizeof dpfree);
        ans += solvefree(0, 0, i);
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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;
const int mod = (1e9) + 7;
const double eps = 1e-6;
const int siz = 5e5 + 5, siz2 = 1049659, siz3 = 5032108;
int t;
long long l, r;
string ls, rs;
int lsz, rsz;
long long dpcomb[21][5][2][2];
long long dp1[21][5][2];
long long dpfree[21][5];
long long solvecomb(int i, int nonzero, int free1, int free2) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == lsz) {
    return 1;
  }
  if (dpcomb[i][nonzero][free1][free2] != -1) {
    return dpcomb[i][nonzero][free1][free2];
  }
  int digl = ls[i] - '0', digr = rs[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free1 == 0 && j < digl) {
      continue;
    }
    if (free2 == 0 && j > digr) {
      continue;
    }
    sum += solvecomb(i + 1, nonzero + (j != 0), free1 || (j > digl),
                     free2 || (j < digr));
  }
  return dpcomb[i][nonzero][free1][free2] = sum;
}
long long solvel(int i, int nonzero, int free1) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == lsz) {
    return 1;
  }
  if (dp1[i][nonzero][free1] != -1) {
    return dp1[i][nonzero][free1];
  }
  int digl = ls[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free1 == 0 && j < digl) {
      continue;
    }
    sum += solvel(i + 1, nonzero + (j != 0), free1 || (j > digl));
  }
  return dp1[i][nonzero][free1] = sum;
}
long long solver(int i, int nonzero, int free2) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == rsz) {
    return 1;
  }
  if (dp1[i][nonzero][free2] != -1) {
    return dp1[i][nonzero][free2];
  }
  int digr = rs[i] - '0';
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    if (free2 == 0 && j > digr) {
      continue;
    }
    sum += solver(i + 1, nonzero + (j != 0), free2 || (j < digr));
  }
  return dp1[i][nonzero][free2] = sum;
}
long long solvefree(int i, int nonzero, int n) {
  if (nonzero > 3) {
    return 0;
  }
  if (i == n) {
    return 1;
  }
  if (dpfree[i][nonzero] != -1) {
    return dpfree[i][nonzero];
  }
  long long sum = 0;
  for (int j = 0; j <= 9; j++) {
    if (j == 0 && i == 0) {
      continue;
    }
    sum += solvefree(i + 1, nonzero + (j != 0), n);
  }
  return dpfree[i][nonzero] = sum;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%I64d%I64d", &l, &r);
    ls = to_string(l);
    rs = to_string(r);
    lsz = ls.size();
    rsz = rs.size();
    if (lsz == rsz) {
      memset(dpcomb, -1, sizeof dpcomb);
      printf("%I64d\n", solvecomb(0, 0, 0, 0));
    } else {
      long long ans = 0;
      memset(dp1, -1, sizeof dp1);
      ans += solvel(0, 0, 0);
      memset(dp1, -1, sizeof dp1);
      ans += solver(0, 0, 0);
      for (int i = lsz + 1; i < rsz; i++) {
        memset(dpfree, -1, sizeof dpfree);
        ans += solvefree(0, 0, i);
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

```