#include <bits/stdc++.h>
int Tim, num[20];
long long M[5][20];
long long run(int x, int cnt, int lim) {
  if (cnt > 3) return 0;
  if (!x) return 1;
  if ((~M[cnt][x]) && !lim) return M[cnt][x];
  long long ans = 0;
  for (int op = lim, i = lim ? num[x] : 9; ~i; i--, op = 0) {
    ans += run(x - 1, cnt + bool(i), op);
  }
  if (!lim) M[cnt][x] = ans;
  return ans;
}
long long solve(long long x) {
  int len = 0;
  while (x) {
    num[++len] = x % 10;
    x /= 10;
  }
  return run(len, 0, 1);
}
int main() {
  scanf("%d", &Tim);
  memset(M, -1, sizeof M);
  while (Tim-- > 0) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    printf("%lld\n", solve(r) - solve(l - 1));
  }
  return 0;
}
