#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(3);
long long dp[3][20][3][5];
long long compute(int fl, int pos, int fl1, int rem) {
  if (rem < 0) {
    return 0;
  }
  if (pos == -1) {
    return 1;
  }
  if (dp[fl][pos][fl1][rem] != -1) {
    return dp[fl][pos][fl1][rem];
  }
  int i, id;
  long long res;
  if (fl1) {
    res = 0;
    for (i = 1; i < 10; i++) {
      res += compute(fl, pos - 1, fl1, rem - 1);
    }
    res += compute(fl, pos - 1, fl1, rem);
    dp[fl][pos][fl1][rem] = res;
  } else {
    res = 0;
    for (i = 1; i < v[fl][pos] + 1; i++) {
      if (i < v[fl][pos]) {
        res += compute(fl, pos - 1, 1, rem - 1);
      } else {
        res += compute(fl, pos - 1, 0, rem - 1);
      }
    }
    if (v[fl][pos] == 0) {
      id = 0;
    } else {
      id = 1;
    }
    res += compute(fl, pos - 1, id, rem);
    dp[fl][pos][fl1][rem] = res;
  }
  return dp[fl][pos][fl1][rem];
}
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long l, r, c = 0, i, j, k, k1, ans;
    cin >> l >> r;
    v[1].clear();
    v[2].clear();
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 20; j++) {
        for (k = 0; k < 2; k++) {
          for (k1 = 0; k1 < 5; k1++) {
            dp[i][j][k][k1] = -1;
          }
        }
      }
    }
    while (r > 0) {
      v[2].push_back(r % 10);
      r /= 10;
    }
    while (l > 0) {
      if (l % 10 != 0) {
        c++;
      }
      v[1].push_back(l % 10);
      l /= 10;
    }
    r = compute(2, (int)v[2].size() - 1, 0, 3);
    l = compute(1, (int)v[1].size() - 1, 0, 3);
    ans = r - l;
    if (c <= 3) {
      ans++;
    }
    cout << ans << endl;
  }
}

### 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;
vector<vector<int> > v(3);
long long dp[3][20][3][5];
long long compute(int fl, int pos, int fl1, int rem) {
  if (rem < 0) {
    return 0;
  }
  if (pos == -1) {
    return 1;
  }
  if (dp[fl][pos][fl1][rem] != -1) {
    return dp[fl][pos][fl1][rem];
  }
  int i, id;
  long long res;
  if (fl1) {
    res = 0;
    for (i = 1; i < 10; i++) {
      res += compute(fl, pos - 1, fl1, rem - 1);
    }
    res += compute(fl, pos - 1, fl1, rem);
    dp[fl][pos][fl1][rem] = res;
  } else {
    res = 0;
    for (i = 1; i < v[fl][pos] + 1; i++) {
      if (i < v[fl][pos]) {
        res += compute(fl, pos - 1, 1, rem - 1);
      } else {
        res += compute(fl, pos - 1, 0, rem - 1);
      }
    }
    if (v[fl][pos] == 0) {
      id = 0;
    } else {
      id = 1;
    }
    res += compute(fl, pos - 1, id, rem);
    dp[fl][pos][fl1][rem] = res;
  }
  return dp[fl][pos][fl1][rem];
}
int main() {
  std::ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long l, r, c = 0, i, j, k, k1, ans;
    cin >> l >> r;
    v[1].clear();
    v[2].clear();
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 20; j++) {
        for (k = 0; k < 2; k++) {
          for (k1 = 0; k1 < 5; k1++) {
            dp[i][j][k][k1] = -1;
          }
        }
      }
    }
    while (r > 0) {
      v[2].push_back(r % 10);
      r /= 10;
    }
    while (l > 0) {
      if (l % 10 != 0) {
        c++;
      }
      v[1].push_back(l % 10);
      l /= 10;
    }
    r = compute(2, (int)v[2].size() - 1, 0, 3);
    l = compute(1, (int)v[1].size() - 1, 0, 3);
    ans = r - l;
    if (c <= 3) {
      ans++;
    }
    cout << ans << endl;
  }
}

```