#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
long long t, L, R, dp[20][4];
long long solve(long long num, int cur, int cnt, long long m) {
  if (cur == 0) return 1;
  long long retval = 0;
  long long tmp = num / m;
  if (tmp) {
    for (int i = 0; i <= cnt; i++) retval += dp[cur - 1][i];
    for (int i = 0; i < cnt; i++) retval += (tmp - 1) * dp[cur - 1][i];
  }
  if (cnt - (tmp ? 1 : 0) >= 0)
    retval += solve(num % m, cur - 1, cnt - (tmp ? 1 : 0), m / 10);
  return retval;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  dp[0][0] = 1;
  dp[1][0] = 1;
  dp[1][1] = 9;
  for (int i = 2; i <= 18; i++) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][0] * 9 + dp[i - 1][1];
    dp[i][2] = dp[i - 1][1] * 9 + dp[i - 1][2];
    dp[i][3] = dp[i - 1][2] * 9 + dp[i - 1][3];
  }
  cin >> t;
  while (t--) {
    cin >> L >> R;
    R = solve(R, 19, 3, 1e18);
    L = solve(L - 1, 19, 3, 1e18);
    cout << R - L << "\n";
  }
  return 0;
}
