#include <bits/stdc++.h>
using namespace std;
long long dp[25][25][2];
vector<int> digits;
long long calc(int pos, int cnt, int f) {
  if (cnt > 3) return 0;
  if (pos == digits.size()) return 1;
  if (dp[pos][cnt][f] != -1) return dp[pos][cnt][f];
  int add;
  if (f)
    add = 9;
  else
    add = digits[pos];
  long long res = 0;
  for (int currdigit = 0; currdigit <= add; currdigit++) {
    int newf = f;
    int newcnt = cnt;
    if (currdigit) newcnt++;
    if (!f && currdigit < add) newf = 1;
    if (newcnt <= 3) res += calc(pos + 1, newcnt, newf);
  }
  return dp[pos][cnt][f] = res;
}
long long solve(long long num) {
  digits.clear();
  while (num) {
    digits.push_back(num % 10);
    num /= 10;
  }
  reverse(digits.begin(), digits.end());
  memset(dp, -1, sizeof(dp));
  long long res = calc(0, 0, 0);
  return res;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << "\n";
  }
}
