#include <bits/stdc++.h>
using namespace std;
vector<long long> ans;
void f(int p, int cnt, long long c) {
  if (p == 18) {
    ans.push_back(c);
    return;
  }
  f(p + 1, cnt, c * 10);
  if (cnt < 3)
    for (int i = 1; i <= 9; ++i) f(p + 1, cnt + 1, c * 10 + i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  f(0, 0, 0);
  ans.push_back(1000000000000000000);
  while (q--) {
    unsigned long long int n, m;
    cin >> n >> m;
    cout << upper_bound(ans.begin(), ans.end(), m) -
                lower_bound(ans.begin(), ans.end(), n)
         << endl;
  }
  return 0;
}
