#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long sti(string x) {
  long long i, res = 0;
  for (i = 0; i < x.size(); i++) res = res * 10 + x[i] - 48;
  return res;
}
void kt(long long x) {
  long long i;
  string s;
  for (i = 0; i < x; i++) s.push_back('0');
  for (int i1 = 1; i1 <= 9; i1++) {
    s[0] = char(i1 + 48);
    for (int j = 1; j < x; j++) {
      for (int j1 = 0; j1 <= 9; j1++) {
        s[j] = char(j1 + 48);
        for (int t = j + 1; t < x; t++) {
          for (int t1 = 0; t1 <= 9; t1++) {
            s[t] = char(t1 + 48);
            v.push_back(sti(s));
          }
          s[t] = '0';
        }
      }
      s[j] = '0';
    }
  }
}
long long tk1(vector<long long> &a, long long l, long long r, long long x) {
  if (l > r) return l;
  long long m = (l + r) / 2;
  if (a[m] == x) return m;
  if (a[m] < x) return tk1(a, m + 1, r, x);
  if (a[m] > x) return tk1(a, l, m - 1, x);
}
long long tk2(vector<long long> &a, long long l, long long r, long long x) {
  if (l > r) return r;
  long long m = (l + r) / 2;
  if (a[m] == x) return m;
  if (a[m] < x) return tk2(a, m + 1, r, x);
  if (a[m] > x) return tk2(a, l, m - 1, x);
}
int main() {
  long long q, t, i, l, r, vt1, vt2;
  cin >> q;
  for (i = 0; i <= 99; i++) v.push_back(i);
  for (i = 3; i <= 19; i++) kt(i);
  set<long long> s(v.begin(), v.end());
  vector<long long> v(s.begin(), s.end());
  for (i = 1; i <= q; i++) {
    cin >> l >> r;
    vt1 = tk1(v, 0, v.size() - 1, l);
    vt2 = tk2(v, 0, v.size() - 1, r);
    cout << vt2 - vt1 + 1 << endl;
  }
  return 0;
}
