#include <bits/stdc++.h>
using namespace std;
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
  os << "(";
  os << v.first << "," << v.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  long long sz = v.size();
  for (long long i = 0; i < sz; ++i) {
    os << v[i];
    if (i != sz - 1) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  T last = *v.rbegin();
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != last) os << ",";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v) {
    os << it.first << " : " << it.second << "\n";
  }
  return os;
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) {
      res = (res * a) % 1000000007;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long dp[22][2][5];
vector<long long> digits;
long long sz = 0;
long long go(long long idx, long long preless, long long cnt) {
  if (idx == sz) {
    return cnt <= 3;
  }
  long long &res = dp[idx][preless][cnt];
  if (res != -1) return res;
  res = 0;
  long long limit = preless ? 9 : digits[idx];
  for (__typeof(0) d = 0; d <= limit; d++) {
    if (d > 0 and cnt > 3) continue;
    res += go(idx + 1, preless || d < digits[idx], cnt + (d > 0));
  }
  return res;
}
long long solve(long long n) {
  digits.clear();
  while (n > 0) {
    digits.push_back(n % 10);
    n /= 10;
  }
  reverse((digits).begin(), (digits).end());
  sz = digits.size();
  memset(dp, -1, sizeof(dp));
  return go(0, 0, 0);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r;
    long long ans = solve(r);
    ans -= solve(l - 1);
    cout << ans << endl;
  }
  return 0;
}
