#include <bits/stdc++.h>
using namespace std;
int T;
long long L, R;
long long mul[25];
long long f[25][5], g[25][5];
long long get(int digits) {
  if (digits <= 3) return mul[digits] - 1;
  long long ret = (1ll * digits * (digits - 1) * (digits - 2) / 6) * 729 +
                  (1ll * digits * (digits - 1) / 2) * 81 + 1ll * digits * 9;
  return ret;
}
long long solve(long long x) {
  if (x == 0) return 0;
  string str = "";
  long long tmp = x;
  while (tmp) {
    str += (char)(tmp % 10 + '0');
    tmp /= 10;
  }
  reverse(str.begin(), str.end());
  long long a = str.size();
  if (a <= 3) return x;
  int cnt = 0;
  for (int i = 0; i < a; i++)
    if (str[i] != '0') cnt++;
  long long t1 = get(a - 1);
  memset(f, 0, sizeof f);
  memset(g, 0, sizeof g);
  g[0][1] = 1;
  f[0][1] = str[0] - '1';
  for (int i = 0; i < a; i++)
    for (int j = 1; j <= min(3, i + 1); j++) {
      if (g[i][j]) {
        for (int k = 0; k < str[i + 1] - '0'; k++)
          f[i + 1][(k == 0) ? j : j + 1] += g[i][j];
        g[i + 1][str[i + 1] == '0' ? j : j + 1] += g[i][j];
      }
      if (f[i][j]) {
        for (int k = 0; k < 10; k++) f[i + 1][(k == 0) ? j : j + 1] += f[i][j];
      }
    }
  long long t2 = 0;
  for (int i = 1; i <= 3; i++) t2 += f[a - 1][i] + g[a - 1][i];
  return t1 + t2;
}
int main() {
  mul[0] = 1;
  for (int i = 1; i <= 18; i++) mul[i] = mul[i - 1] * 10;
  cin >> T;
  while (T--) {
    cin >> L >> R;
    cout << solve(R) - solve(L - 1) << endl;
  }
  return 0;
}
