#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3 * 1e5 + 5;
const int MOD = 1e9 + 7;
int brute(int n) {
  int c = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    int zero = count(s.begin(), s.end(), '0');
    if (s.length() - zero <= 3) {
      c++;
    }
  }
  return c;
}
int l;
string s;
long long int dp[20][5][3];
long long int solve(int index, int non_zeroes, bool cap) {
  if (non_zeroes > 3) {
    return 0;
  }
  if (index >= l) {
    return 1;
  }
  if (dp[index][non_zeroes][cap] != -1) {
    return dp[index][non_zeroes][cap];
  }
  if (index == 0) {
    int val = s[index] - '0';
    long long int ans = 0;
    for (int i = 1; i <= val; i++) {
      if (i < val) {
        ans += solve(index + 1, non_zeroes + 1, 0);
      } else {
        ans += solve(index + 1, non_zeroes + 1, 1);
      }
    }
    return dp[index][non_zeroes][cap] = ans;
  } else {
    int val = s[index] - '0';
    long long int ans = 0;
    if (cap) {
      for (int i = 0; i <= val; i++) {
        if (i == 0) {
          if (i < val)
            ans += solve(index + 1, non_zeroes, 0);
          else
            ans += solve(index + 1, non_zeroes, 1);
        } else {
          if (i < val)
            ans += solve(index + 1, non_zeroes + 1, 0);
          else
            ans += solve(index + 1, non_zeroes + 1, 1);
        }
      }
    } else {
      for (int i = 0; i <= 9; i++) {
        if (i == 0) {
          ans += solve(index + 1, non_zeroes, cap);
        } else {
          ans += solve(index + 1, non_zeroes + 1, cap);
        }
      }
    }
    return dp[index][non_zeroes][cap] = ans;
  }
}
long long int nines[20];
void pre() {
  s = "";
  for (int i = 1; i <= 18; i++) {
    memset(dp, -1, sizeof(dp));
    s += "9";
    l = i;
    nines[i] = solve(0, 0, 0);
  }
}
long long int value(long long int n) {
  if (n == 0) return 0;
  memset(dp, -1, sizeof(dp));
  s = to_string(n);
  l = s.length();
  long long int ans = solve(0, 0, 0);
  s = "";
  int templ = l;
  for (int i = 1; i < templ; i++) {
    ans += nines[i];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pre();
  int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    cout << value(b) - value(a - 1) << '\n';
  }
}

### Prompt

Please create a solution in cpp 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;
const int MAXN = 3 * 1e5 + 5;
const int MOD = 1e9 + 7;
int brute(int n) {
  int c = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    int zero = count(s.begin(), s.end(), '0');
    if (s.length() - zero <= 3) {
      c++;
    }
  }
  return c;
}
int l;
string s;
long long int dp[20][5][3];
long long int solve(int index, int non_zeroes, bool cap) {
  if (non_zeroes > 3) {
    return 0;
  }
  if (index >= l) {
    return 1;
  }
  if (dp[index][non_zeroes][cap] != -1) {
    return dp[index][non_zeroes][cap];
  }
  if (index == 0) {
    int val = s[index] - '0';
    long long int ans = 0;
    for (int i = 1; i <= val; i++) {
      if (i < val) {
        ans += solve(index + 1, non_zeroes + 1, 0);
      } else {
        ans += solve(index + 1, non_zeroes + 1, 1);
      }
    }
    return dp[index][non_zeroes][cap] = ans;
  } else {
    int val = s[index] - '0';
    long long int ans = 0;
    if (cap) {
      for (int i = 0; i <= val; i++) {
        if (i == 0) {
          if (i < val)
            ans += solve(index + 1, non_zeroes, 0);
          else
            ans += solve(index + 1, non_zeroes, 1);
        } else {
          if (i < val)
            ans += solve(index + 1, non_zeroes + 1, 0);
          else
            ans += solve(index + 1, non_zeroes + 1, 1);
        }
      }
    } else {
      for (int i = 0; i <= 9; i++) {
        if (i == 0) {
          ans += solve(index + 1, non_zeroes, cap);
        } else {
          ans += solve(index + 1, non_zeroes + 1, cap);
        }
      }
    }
    return dp[index][non_zeroes][cap] = ans;
  }
}
long long int nines[20];
void pre() {
  s = "";
  for (int i = 1; i <= 18; i++) {
    memset(dp, -1, sizeof(dp));
    s += "9";
    l = i;
    nines[i] = solve(0, 0, 0);
  }
}
long long int value(long long int n) {
  if (n == 0) return 0;
  memset(dp, -1, sizeof(dp));
  s = to_string(n);
  l = s.length();
  long long int ans = solve(0, 0, 0);
  s = "";
  int templ = l;
  for (int i = 1; i < templ; i++) {
    ans += nines[i];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  pre();
  int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    cout << value(b) - value(a - 1) << '\n';
  }
}

```