#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 300005;
const double PI = 4 * atan(1);
const long long MAX = 9223372036854775807;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }
bool isprime(long long u) {
  for (long long i = 2; i <= (int)sqrt(u); i++) {
    if (u % i == 0) return 0;
  }
  return 1;
}
long long mod(long long to_mod, long long MOD) {
  to_mod %= MOD;
  while (to_mod < 0) to_mod += MOD;
  return to_mod % MOD;
}
long long moduloMultiplication(long long a, long long b, long long mod) {
  long long res = 0;
  a %= mod;
  while (b) {
    if (b & 1) res = (res + a) % mod;
    a = (2 * a) % mod;
    b >>= 1;
  }
  return res;
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long n, m, x, y, res, t, k, q, z, w, l, r, ans;
vector<long long> v;
long long b[20];
long long getmin(long long u) {
  long long l = 0;
  long long r = k - 1;
  while (l != r - 1) {
    long long mid = (l + r) / 2;
    if (v[mid] > u) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (v[l] >= u) return l;
  return r;
}
long long getmax(long long u) {
  long long l = 0;
  long long r = k - 1;
  while (l != r - 1) {
    long long mid = (l + r) / 2;
    if (v[mid] > u) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (v[r] <= u) return r;
  return l;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  b[0] = 1;
  for (int i = 1; i <= 18; i++) {
    b[i] = 10 * b[i - 1];
  }
  for (int i = 0; i < 18; i++) {
    for (int j = 1; j <= 9; j++) {
      x = b[i] * j;
      for (int k = i + 1; k < 18; k++) {
        for (int u = 1; u <= 9; u++) {
          y = x + b[k] * u;
          for (int o = k + 1; o < 18; o++) {
            for (int r = 1; r <= 9; r++) {
              z = y + b[o] * r;
              if (z < 1e18 && z >= 1) v.push_back(z);
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < 18; i++) {
    for (int j = 1; j <= 9; j++) {
      x = b[i] * j;
      for (int k = i + 1; k < 18; k++) {
        for (int u = 1; u <= 9; u++) {
          y = x + b[k] * u;
          if (y < 1e18 && y >= 1) {
            v.push_back(y);
          }
        }
      }
    }
  }
  for (int i = 0; i < 18; i++) {
    for (int j = 1; j <= 9; j++) {
      x = b[i] * j;
      if (x < 1e18 && x >= 1) v.push_back(x);
    }
  }
  v.push_back(1000000000000000000);
  k = v.size();
  sort(v.begin(), v.end());
  while (n--) {
    cin >> x >> y;
    x = getmin(x);
    y = getmax(y);
    cout << max(y - x + 1, 0ll) << endl;
  }
  return 0;
}
