#include <bits/stdc++.h>
using namespace std;
long long abso(long long a) { return a > 0 ? a : (-a); }
long long cdiv(long long a, long long b) { return a / b + ((a % b) > 0); }
long long mul(long long a, long long b) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % 998244353;
    a = (a + a) % 998244353;
    b = b / 2;
  }
  return res;
}
long long bexp(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b = b / 2;
  }
  return res;
}
long long inv(long long a) { return bexp(a, 998244353 - 2); }
long long nCr(long long n, long long r) {
  long long fac[10];
  return mul(fac[n], mul(inv(fac[n - r]), inv(fac[r])));
}
struct compare {
  bool operator()(const long long& lhs, const long long& rhs) const {
    return lhs % 10 > rhs % 10;
  }
};
long long sz = 0;
long long x[20];
long long cache[20][2][5];
long long solve(long long idx, long long less, long long taken) {
  if (taken > 3) return 0;
  if (idx == sz) return 1;
  long long& ans = cache[idx][less][taken];
  if (ans != -1) return ans;
  ans = 0;
  if (!less) {
    for (long long dig = 0; dig <= x[idx]; dig++)
      ans += solve(idx + 1, less | dig < x[idx], taken + (dig > 0));
  } else {
    for (long long dig = 0; dig <= 9; dig++)
      ans += solve(idx + 1, 1, taken + (dig > 0));
  }
  return ans;
}
long long f(long long k) {
  memset(cache, -1, sizeof(cache));
  sz = 0;
  while (k > 0) {
    x[sz++] = k % 10;
    k /= 10;
  }
  reverse(x, x + sz);
  long long ans = solve(0, 0, 0);
  return ans;
}
void solve() {
  long long l, r;
  cin >> l >> r;
  cout << f(r) - f(l - 1) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
