#include <bits/stdc++.h>
using LL = long long;
using namespace std;
vector<LL> numbers;
int countClassy(LL limit) {
  auto position =
      std::lower_bound(std::begin(numbers), std::end(numbers), limit);
  return position - std::begin(numbers);
}
LL getPow10(int exponent) {
  LL p = 1;
  while (exponent--) {
    p *= 10;
  }
  return p;
}
void bk(int position, LL currNumber, int leftNonZeroes) {
  if (position > 18) {
    numbers.push_back(currNumber);
    return;
  }
  bk(position + 1, currNumber, leftNonZeroes);
  LL pow10 = getPow10(position);
  if (leftNonZeroes >= 1) {
    for (int digit = 1; digit <= 9; ++digit) {
      bk(position + 1, currNumber + digit * pow10, leftNonZeroes - 1);
    }
  }
}
int main() {
  bk(0, 0, 3);
  std::sort(begin(numbers), end(numbers));
  int q;
  cin >> q;
  LL l, r;
  while (q--) {
    cin >> l >> r;
    cout << countClassy(r + 1) - countClassy(l) << '\n';
  }
  return 0;
}
