#include <bits/stdc++.h>
using namespace std;
const long long OO = (long long)(1e18) + 9;
const long long MOD = (long long)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dX[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dY[] = {0, 1, 0, -1, 1, 1, -1, -1};
string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou";
int dcmp(long double d1, long double d2) {
  return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1;
}
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int ord(int r, int c, int nCol) { return (nCol * r) + c + 1; }
pair<int, int> rord(int n, int nCol) {
  int r = n % nCol, c = n / nCol;
  if (n % nCol == 0) c--, r = nCol;
  return pair<int, int>(r, c);
}
long long poww(long long num, long long p, long long md) {
  num %= md;
  long long ret = 1;
  while (p > 0) {
    if (p & 1) ret = (ret * num) % md;
    num = (num * num) % md;
    p >>= 1;
  }
  return ret;
}
long long nCr(long long n, long long r) {
  if (n < r) return 0;
  if (r == 0) return 1;
  return n * nCr(n - 1, r - 1) / r;
}
long long dp[20][10][2][2];
string L, R;
long long solve(int idx, int rest, int l, int r) {
  if (rest < 0) return 0;
  if (idx == (int)R.size()) return 1;
  long long& tmp = dp[idx][rest][l][r];
  if (~tmp) return tmp;
  tmp = 0;
  for (int i = 0; i < 10; i++) {
    if (!l && i < L[idx] - '0') continue;
    if (!r && i > R[idx] - '0') continue;
    tmp += solve(idx + 1, rest - (i != 0), l || (i > L[idx] - '0'),
                 r || (i < R[idx] - '0'));
  }
  return tmp;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(dp, -1, sizeof dp);
    cin >> L >> R;
    int dif = (int)R.size() - (int)L.size();
    while (dif--) L = "0" + L;
    printf("%lld\n", solve(0, 3, 0, 0));
  }
  return 0;
}
