#include <bits/stdc++.h>
using namespace std;
int nTest;
long long Count[20][4];
long long Base[20];
int lis[20];
int nLis;
long long Cal(long long value) {
  if (!value) return 0;
  long long ans = 0;
  for (int i = 1; Base[i] - 1 < value; ++i) {
    ans += (Count[i - 1][0] + Count[i - 1][1] + Count[i - 1][2]) * 9ll;
  }
  long long foo = value;
  while (foo) {
    lis[++nLis] = foo % 10;
    foo /= 10;
  }
  int cur = 0;
  reverse(lis + 1, lis + nLis + 1);
  for (int i = 1; i <= nLis; ++i) {
    int bar = max(0, lis[i] - 1);
    for (int j = 0; j < 3 - cur; ++j) ans += 1ll * bar * Count[nLis - i][j];
    if (lis[i] && i != 1) {
      for (int j = 0; j <= 3 - cur; ++j) ans += Count[nLis - i][j];
    }
    if (lis[i]) cur++;
    if (cur == 3 || i == nLis) {
      ans++;
      break;
    }
  }
  nLis = 0;
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> nTest;
  Count[0][0] = 1;
  Count[1][1] = 9;
  Count[1][0] = 1;
  Base[0] = 1;
  for (int i = 1; i <= 18; ++i) Base[i] = Base[i - 1] * 10;
  for (int i = 2; i <= 18; ++i) {
    for (int num = 0; num <= 2; ++num) {
      Count[i][num] = Count[i - 1][num];
      if (num) Count[i][num] += 9ll * Count[i - 1][num - 1];
    }
  }
  while (nTest--) {
    long long l, r;
    cin >> l >> r;
    long long ans = 0;
    if (r == (long long)1e18) ans++, r--;
    ans += Cal(r) - Cal(l - 1);
    cout << ans << endl;
  }
  return 0;
}
