#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }
string s = "";
long long arr[20] = {0};
long long brr[1000005] = {0};
long long pw[20] = {0};
vector<long long> v;
vector<long long> g[1000005];
long long num(long long x) {
  long long ans = 0;
  while (x > 0) {
    x /= 10;
    ans++;
  }
  return ans;
}
long long fir(long long x) {
  long long ans = 0;
  while (1) {
    if (x < 10) return x;
    x /= 10;
  }
}
long long solve(long long x) {
  if (x < 1000) return x;
  long long ans = 999;
  long long nz = num(x);
  for (int i = 4; i < nz; i++) {
    ans += arr[i];
  }
  long long f = fir(x);
  ans += (f - 1) * ((81 * (nz - 1) * (nz - 2)) / 2 + 9 * (nz - 1) + 1);
  x -= f * pw[nz - 1];
  nz = num(x);
  f = fir(x);
  if (x < 100) {
    ans += x;
    return ans + 1;
  }
  ans += (f - 1) * (9 * (nz - 1) + 1);
  ans += 81 * (nz - 1) * (nz - 2) / 2 + 9 * (nz - 1) + 1;
  x -= f * pw[nz - 1];
  nz = num(x);
  f = fir(x);
  if (x < 10) {
    ans += x;
    return ans + 1;
  }
  ans += (f - 1);
  ans += 9 * (nz - 1) + 1;
  return ans + 1;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n = 0, m = 0, k = 0, q = 0, ans = 0;
  long long x = 0, y = 0, t = 0, sum = 0, sz = 0;
  for (long long i = 4; i < 20; i++) {
    arr[i] = 9 * (81 * (i - 1) * (i - 2) / 2 + 9 * (i - 1) + 1);
  }
  pw[0] = 1;
  for (int i = 1; i <= 18; i++) {
    pw[i] = pw[i - 1] * 10;
  }
  cin >> t;
  while (t--) {
    cin >> x >> y;
    y = solve(y);
    x = solve(x - 1);
    cout << y - x << endl;
  }
  return 0;
}
