#include <bits/stdc++.h>
long long int dp(long long int now, long long int pos, int cnt) {
  if (pos == 0) return 1;
  if (cnt == 3) return 1;
  long long int ans = dp(now, pos / 10, cnt), p;
  for (p = 0; p < 10; p++)
    if (pos * p > now) break;
  p--;
  if (p > 0)
    ans += (p - 1) * dp(now - pos, pos / 10, cnt + 1) +
           dp(now - pos * p, pos / 10, cnt + 1);
  return ans;
}
int main() {
  int t;
  long long int l, r;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &l, &r);
    printf("%lld\n", dp(r, 1e18, 0) - dp(l - 1, 1e18, 0));
  }
}
