#include <bits/stdc++.h>
using namespace std;
string a, b;
long long dp[4][19][2];
long long F(int cnt, int pos, bool zero) {
  if (cnt > 3) {
    return 0;
  }
  if (pos >= (int)b.size()) {
    return 1;
  }
  long long& ret = dp[cnt][pos][zero];
  if (ret != -1) {
    return ret;
  }
  ret = 0;
  for (int i = 0; i <= 9; i++) {
    if (zero == false && i > (b[pos] - '0')) break;
    ret +=
        F(cnt + (i != 0), pos + 1, zero == true ? zero : ((b[pos] - '0') > i));
  }
  return ret;
}
void solve() {
  cin >> a >> b;
  for (int i = (int)a.size() - 1; i >= 0; i--) {
    if (a[i] == '0') {
      a[i] = '9';
      continue;
    }
    a[i]--;
    break;
  }
  memset(dp, -1, sizeof dp);
  long long ans = F(0, 0, 0);
  swap(a, b);
  memset(dp, -1, sizeof dp);
  cout << ans - F(0, 0, 0) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
