#include <bits/stdc++.h>
using namespace std;
long long memo[20][20][2];
long long DP(long long digit_ke, long long cnt0, long long flag, string R) {
  if (digit_ke >= R.length()) {
    if (cnt0 <= 3)
      return 1;
    else
      return 0;
  }
  if (memo[digit_ke][cnt0][flag] != -1) return memo[digit_ke][cnt0][flag];
  long long ans = 0;
  if (flag == 1) {
    if (R[digit_ke] == '0') {
      ans += DP(digit_ke + 1, cnt0, 1, R);
    } else {
      ans += DP(digit_ke + 1, cnt0 + 1, 1, R);
    }
    for (long long dig = 0; dig < (long long)(R[digit_ke] - '0'); dig++) {
      if (dig == 0) {
        ans += DP(digit_ke + 1, cnt0, 0, R);
      } else {
        ans += DP(digit_ke + 1, cnt0 + 1, 0, R);
      }
    }
  } else {
    for (long long dig = 0; dig <= 9; dig++) {
      if (dig == 0) {
        ans += DP(digit_ke + 1, cnt0, 0, R);
      } else {
        ans += DP(digit_ke + 1, cnt0 + 1, 0, R);
      }
    }
  }
  return memo[digit_ke][cnt0][flag] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    memset(memo, -1, sizeof(memo));
    string L, R;
    cin >> L >> R;
    long long res1 = DP(0, 0, 1, R);
    memset(memo, -1, sizeof(memo));
    long long res2 = DP(0, 0, 1, L);
    long long berapa = 0;
    for (long long i = 0; i < L.length(); i++) {
      if (L[i] != '0') berapa++;
    }
    if (berapa <= 3) res2--;
    cout << res1 - res2 << endl;
  }
  return 0;
}
