#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long BIG = (long long)(1e9 + 239);
const long long MOD = 998244353;
const long double PI = 2.0 * acos(0.0);
const long double EPS = static_cast<long double>(1e-10);
const long long day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
mt19937 rnd(239);
void FILEIO() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void input() {}
vector<long long> num;
long long a, b, k = 3;
long long DP[21][6][2];
long long call(long long pos, long long cnt, long long f) {
  if (cnt > k) {
    return 0;
  }
  if (pos == ((long long)(num).size())) {
    if (cnt <= k) {
      return 1;
    }
    return 0;
  }
  if (DP[pos][cnt][f] != -1) {
    return DP[pos][cnt][f];
  }
  long long res = 0;
  long long LMT;
  if (f == 0) {
    LMT = num[pos];
  } else {
    LMT = 9;
  }
  for (long long dgt = 0; dgt <= LMT; dgt++) {
    long long nf = f;
    long long ncnt = cnt;
    if (f == 0 && dgt < LMT) nf = 1;
    if (dgt != 0) ncnt++;
    if (ncnt <= k) {
      res += call(pos + 1, ncnt, nf);
    }
  }
  return DP[pos][cnt][f] = res;
}
long long solve(long long b) {
  num.clear();
  while (b > 0) {
    num.push_back(b % 10);
    b /= 10;
  }
  reverse(num.begin(), num.end());
  memset(DP, -1, sizeof(DP));
  long long res = call(0, 0, 0);
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  long long t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << endl;
    ;
  }
  return 0;
}
