#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
string s(18, '0');
vector<long long> ans;
void dfs(int cur, int cnt) {
  if (cur == 18) {
    ans.push_back(stoll(s));
    return;
  }
  if (cnt < 3) {
    for (char c = '1'; c <= '9'; c++) {
      s[cur] = c;
      dfs(cur + 1, cnt + 1);
    }
  }
  s[cur] = '0';
  dfs(cur + 1, cnt);
}
int main() {
  int t;
  cin >> t;
  dfs(0, 0);
  long long l, r;
  sort(ans.begin(), ans.end());
  ans.push_back((long long)1e18);
  while (t--) {
    cin >> l >> r;
    cout << upper_bound(ans.begin(), ans.end(), r) -
                lower_bound(ans.begin(), ans.end(), l)
         << endl;
  }
  return 0;
}
