#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long INF = (1LL << 61);
const int inf = (1 << 30);
const int nn = 1e6 + 5;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\t';
  err(++it, args...);
}
vector<int> v;
int N;
long long fun(int i, bool eq, int now) {
  if (i == N || now == 3) return 1;
  long long cnt = 0;
  if (eq) {
    if (v[i] > 0) {
      cnt += (v[i] - 1) * fun(i + 1, 0, now + 1);
      cnt += fun(i + 1, 1, now + 1);
      cnt += fun(i + 1, 0, now);
    } else {
      cnt += fun(i + 1, 1, now);
    }
  } else {
    cnt += 9 * fun(i + 1, 0, now + 1);
    cnt += fun(i + 1, 0, now);
  }
  return cnt;
}
void convert(long long n) {
  v.clear();
  while (n) {
    v.push_back(n % 10);
    n /= 10;
  }
  reverse(v.begin(), v.end());
  N = ((int)(v).size());
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    convert(b);
    long long ans = fun(0, 1, 0);
    convert(a - 1);
    ans -= fun(0, 1, 0);
    cout << ans << '\n';
  }
  return 0;
}
