#include <bits/stdc++.h>
using namespace std;
int f(long long n, int k) {
  if (k == 0 || n == 0) return 0;
  if (n < 10) return n;
  return 9 + f(n / 10, k) + (9 - n % 10) * f(n / 10 - 1, k - 1) +
         n % 10 * f(n / 10, k - 1);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long l, r;
    cin >> l >> r, cout << f(r, 3) - f(l - 1, 3) << "\n";
  }
}
