#include <bits/stdc++.h>
using namespace std;
long long cr(long long n, long long r) {
  if (r > n) return 0;
  if (r == 0) return 1;
  if (r == 1) return n;
  if (r == 2) {
    return (n * (n - 1)) / 2LL;
  }
  if (r == 3) {
    return (n * (n - 1) * (n - 2)) / (6LL);
  }
}
long long fn(string s) {
  s = '0' + s;
  long long ans = 0;
  long long i, j, k;
  long long n = s.size();
  k = 0;
  long long r = 0;
  for (i = 0; i < n; i++) {
    long long digi = (s[i] - '0');
    if (digi == 0) continue;
    for (r = 0; r <= 3; r++) {
      if (r + k <= 3) ans += (cr(n - i - 1, r) * pow(9, r));
      if (digi != 0 && r + k + 1 <= 3)
        ans += (digi - 1) * (cr(n - i - 1, r) * pow(9, r));
    }
    if (digi != 0) k++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    y++;
    long long i;
    string a, b;
    a = to_string(x);
    b = to_string(y);
    long long ans = fn(b) - fn(a);
    cout << ans << endl;
  }
}
