#include <bits/stdc++.h>
using namespace std;
string num;
long long memo[2][20][4];
long long go(bool lt = false, int n = 0, int nz = 0) {
  if (nz >= 4) return 0;
  if (n >= int((num).size())) return 1;
  long long& res = memo[lt][n][nz];
  if (res < 0) {
    res = 0;
    for (int d = (0), _b = (lt ? 9 : num[n] - '0'); d <= _b; ++d) {
      res += go(lt || d < num[n] - '0', n + 1, nz + (d > 0));
    }
  }
  return res;
}
long long F(long long R) {
  num = to_string(R);
  memset(memo, -1, sizeof(memo));
  return go();
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int Q;
  cin >> Q;
  for (int q = (1), _b = (Q); q <= _b; ++q) {
    long long L, R;
    cin >> L >> R;
    long long res = F(R) - F(L - 1);
    cout << res << '\n';
  }
  return 0;
}
