#include <bits/stdc++.h>
using namespace std;
long long C[20][20];
long long cal(long long dic, long long cur) {
  cur = min(dic, cur);
  long long ans = 0;
  long long ppow = 1;
  for (int i = 0; i <= cur; ++i) {
    ans += C[dic][i] * ppow;
    ppow *= 9;
  }
  return ans;
}
long long Solve(long long num, int cur) {
  if (cur == 0 || num == 0) return (long long)1;
  int dic = 1;
  long long tnum = num;
  while (tnum /= 10) ++dic;
  long long tmp = 1;
  for (int i = 2; i <= dic; ++i) tmp *= 10;
  long long k = num / tmp;
  long long ans = (k - 1) * cal(dic - 1, cur - 1);
  ans += cal(dic - 1, cur);
  ans += Solve(num % tmp, cur - 1);
  return ans;
}
int main() {
  C[0][0] = 1;
  for (int i = 1; i <= 18; ++i) {
    for (int j = 0; j <= i; ++j) {
      C[i][j] = C[i - 1][j];
      if (j != 0) C[i][j] += C[i - 1][j - 1];
    }
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    long long L, R;
    scanf("%lld %lld", &L, &R);
    printf("%lld\n", Solve(R, 3) - Solve(L - 1, 3));
  }
}
