#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
void gen(long long at, long long cur, long long cnt) {
  if (at == 18) {
    v.push_back(cur);
    return;
  }
  gen(at + 1, cur * 10, cnt);
  if (cnt < 3)
    for (long long i = 1; i <= 9; i++) gen(at + 1, cur * 10 + i, cnt + 1);
}
int main() {
  gen(0, 0, 0);
  sort(v.begin(), v.end());
  v.push_back(1e18);
  long long i, j, t;
  long long l, r, n;
  cin >> t;
  while (t--) {
    cin >> l >> r;
    int R = upper_bound(v.begin(), v.end(), r) - v.begin();
    int L = lower_bound(v.begin(), v.end(), l) - v.begin();
    cout << R - L << endl;
  }
  return 0;
}
