#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int f[N][2][N], a[N];
long long solve(int u, bool limit, int prev) {
  if (u == -1) return 1;
  if (!limit && f[u][limit][prev] != -1) return f[u][limit][prev];
  int up = limit ? a[u] : 9;
  long long res = 0;
  for (int i = 0; i <= up; ++i) {
    if (i == 0)
      res += solve(u - 1, limit && (a[u] == i), prev);
    else if (prev != 3)
      res += solve(u - 1, limit && (a[u] == i), prev + 1);
  }
  if (!limit) f[u][limit][prev] = res;
  return res;
}
long long solve(long long x) {
  int tot = 0;
  while (x) {
    a[tot++] = x % 10;
    x /= 10;
  }
  return solve(tot - 1, 1, 0);
}
int main() {
  memset(f, -1, sizeof f);
  int T;
  scanf("%d", &T);
  while (T--) {
    long long l, r;
    scanf("%lld%lld", &l, &r);
    printf("%lld\n", solve(r) - solve(l - 1));
  }
  return 0;
}
