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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
vector<bool> prime;
vector<long long> fact, inv, primes, factors;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void factorize(long long a) {
  factors.clear();
  for (long long i = 1; i * i <= a; i++) {
    if (i * i == a)
      factors.push_back(i);
    else if (a % i == 0) {
      factors.push_back(i);
      factors.push_back(a / i);
    }
  }
  sort(factors.begin(), factors.end());
}
long long power(long long a, long long b) {
  if (a == 1 || b == 0) return 1;
  long long c = power(a, b / 2);
  long long res = 1;
  res = c * c;
  if (res >= 1000000007) res %= 1000000007;
  if (b % 2) res *= a;
  if (res >= 1000000007) res %= 1000000007;
  return res;
}
long long modInv(long long a) { return power(a, 1000000007 - 2); }
void factorial(long long n) {
  fact.resize(n + 1);
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i;
    if (fact[i] >= 1000000007) fact[i] %= 1000000007;
  }
}
void InvFactorial(long long n) {
  inv.resize(n + 1);
  inv[0] = 1;
  for (long long i = 1; i <= n; i++) inv[i] = modInv(fact[i]);
}
long long ncr(long long n, long long r) {
  if (n < r || n < 0 || r < 0) return 0;
  long long b = inv[n - r];
  long long c = inv[r];
  long long a = fact[n] * b;
  if (a >= 1000000007) a %= 1000000007;
  a *= c;
  if (a >= 1000000007) a %= 1000000007;
  return a;
}
void remove_duplicates(vector<pair<long long, long long>> &v) {
  sort(v.begin(), v.end());
  long long _size = unique(v.begin(), v.end()) - v.begin();
  v.resize(_size);
}
unsigned long long gcd(unsigned long long u, unsigned long long v) {
  if (u == 0 || v == 0) return max(u, v);
  unsigned long long shift = __builtin_ctz(u | v);
  u >>= __builtin_ctz(u);
  do {
    v >>= __builtin_ctz(v);
    if (u > v) swap(u, v);
    v -= u;
  } while (v != 0);
  return u << shift;
}
void sieve(long long n) {
  prime.assign(n + 1, 1);
  prime[1] = false;
  for (long long p = 2; p * p <= n; p++)
    if (prime[p])
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
  for (long long i = 2; i < n + 1; i++)
    if (prime[i]) primes.push_back(i);
}
long long size(long long l) {
  long long p = l;
  long long count = 0;
  while (p) p /= 10, count++;
  return count;
}
set<long long> s;
set<pair<long long, long long>> aotn;
void find_aotn() {
  long long tens[20];
  tens[0] = 1;
  for (long long i = 1; i < 20; i++) {
    tens[i] = tens[i - 1] * 10;
  }
  for (long long i = 17; i >= -1; i--) {
    for (long long j = i - 1; j >= -2; j--) {
      for (long long k = j - 1; k >= -3; k--) {
        for (long long a1 = 1; a1 <= 9; a1++) {
          for (long long a2 = 1; a2 <= 9; a2++) {
            for (long long a3 = 1; a3 <= 9; a3++) {
              long long n = 0;
              if (i >= 0) n += a1 * tens[i];
              if (j >= 0) n += a2 * tens[j];
              if (k >= 0) n += a3 * tens[k];
              s.insert(n);
            }
          }
        }
      }
    }
  }
  s.insert(1000000000000000000);
  long long count = 0;
  for (auto i1 = s.begin(); i1 != s.end(); i1++) {
    aotn.insert({*i1, count});
    count++;
  }
}
void solve() {
  long long l, r;
  cin >> l >> r;
  long long ansl = -1, ansr = aotn.size();
  set<pair<long long, long long>>::iterator i1, i2;
  i1 = aotn.lower_bound({l, -1});
  ansl = (*i1).second;
  i2 = aotn.upper_bound({r, 1000000000000});
  i2--;
  ansr = (*i2).second + 1;
  cout << ansr - ansl << '\n';
}
signed main() {
  fast();
  find_aotn();
  long long T = 1;
  cin >> T;
  for (long long i = 1; i <= T; i++) solve();
}