#include <bits/stdc++.h>
using namespace std;
long long dp[20][5][2];
string s;
long long l, r;
long long solve(long long pos, long long cnt, bool tight) {
  if (pos == s.size()) return 1;
  if (dp[pos][cnt][tight] != -1) return dp[pos][cnt][tight];
  long long ret = 0;
  long long en = tight ? (s[pos] - '0') : 9;
  for (long long i = 0; i <= en; i++) {
    long long c = cnt + (i > 0);
    if (c <= 3) {
      ret += solve(pos + 1, c, tight & (i == en));
    }
  }
  return dp[pos][cnt][tight] = ret;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> l >> r;
    s = to_string(r);
    memset(dp, -1, sizeof dp);
    long long ans = solve(0, 0, 1);
    l -= 1;
    s = to_string(l);
    memset(dp, -1, sizeof dp);
    ans -= solve(0, 0, 1);
    cout << ans << endl;
  }
  return 0;
}
