#include <bits/stdc++.h>
using namespace std;
long long count_classy(long long N) {
  if (N == 0) return 0;
  string S = to_string(N);
  long long res = 0;
  for (int l = 1; l < S.size(); l++) {
    res += 9 * (1 + 9 * (l - 1) + 9 * 9 * (l - 1) * (l - 2) / 2);
  }
  int non_zero = 3;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0') continue;
    int l = S.size() - i;
    if (i > 0) {
      if (non_zero >= 0) res += 1;
      if (non_zero >= 1) res += 9 * (l - 1);
      if (non_zero >= 2) res += 9 * 9 * (l - 1) * (l - 2) / 2;
    }
    non_zero--;
    if (non_zero < 0) break;
    int d = S[i] - '0' - 1;
    if (non_zero >= 0) res += d;
    if (non_zero >= 1) res += d * 9 * (l - 1);
    if (non_zero >= 2) res += d * 9 * 9 * (l - 1) * (l - 2) / 2;
  }
  if (non_zero >= 0) res++;
  return res;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long L, R;
    scanf("%lld%lld", &L, &R);
    printf("%lld\n", count_classy(R) - count_classy(L - 1));
  }
}
