#include <bits/stdc++.h>
using namespace std;
long long a[30000000];
int m;
void dfs(int x, long long s, int k) {
  if (k > 3) return;
  if (x == 18) {
    a[m++] = s;
    return;
  }
  dfs(x + 1, s * 10, k);
  for (int i = 1; i <= 9; i++) {
    dfs(x + 1, s * 10 + i, k + 1);
  }
  return;
}
int main() {
  int t;
  long long x, y;
  m = 0;
  dfs(0, 0, 0);
  a[m++] = 1000000000000000000;
  sort(a, a + m);
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &x, &y);
    x = upper_bound(a, a + m, x - 1) - 1 - a;
    y = upper_bound(a, a + m, y) - 1 - a;
    printf("%lld\n", y - x);
  }
  return 0;
}
