#include <bits/stdc++.h>
using namespace std;
long long dp[60][5];
long long a[30];
long long dfs(int pos, int pre, bool limit) {
  if (pre > 3) return 0;
  if (pos == -1 && pre <= 3)
    return 1;
  else if (pos == -1)
    return 0;
  if (!limit && dp[pos][pre] != -1) return dp[pos][pre];
  int up = limit ? a[pos] : 9;
  int sum = 0;
  for (int i = 0; i <= up; i++) {
    sum += dfs(pos - 1, pre + (i != 0), limit && i == a[pos]);
  }
  if (!limit) dp[pos][pre] = sum;
  return sum;
}
long long solve(long long k) {
  int pos = 0;
  while (k) {
    a[pos++] = k % 10;
    k /= 10;
  }
  long long ans = dfs(pos - 1, 0, 1);
  return ans;
}
int main() {
  int t;
  long long n, m;
  scanf("%d", &t);
  memset(dp, -1, sizeof(dp));
  while (t--) {
    memset(a, 0, sizeof(a));
    scanf("%lld%lld", &n, &m);
    printf(t == 0 ? "%lld" : "%lld\n", solve(m) - solve(n - 1));
  }
  return 0;
}
