#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
const long long inf = 0x3f3f3f3fll;
const long long mod = 998244353ll;
int n, m;
long long po[20];
long long q[N];
long long s[N];
long long l[N], r[N];
int len;
void dfs(long long num, int step, int cnt) {
  if (step == 19) {
    int k = lower_bound(q + 1, q + n * 2 + 1, num) - q;
    s[k]++;
    return;
  }
  if (cnt < 3) {
    for (int i = 1; i <= 9; i++) {
      long long tmp = num + i * po[step];
      dfs(tmp, step + 1, cnt + 1);
    }
  }
  dfs(num, step + 1, cnt);
}
int main() {
  ios::sync_with_stdio(0);
  int i, j;
  cin >> n;
  po[0] = 1;
  for (i = 1; i < 20; i++) po[i] = po[i - 1] * 10ll;
  for (i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    q[++len] = l[i] - 1;
    q[++len] = r[i];
  }
  sort(q + 1, q + 2 * n + 1);
  dfs(0, 0, 0);
  for (i = 1; i <= 2 * n; i++) s[i] += s[i - 1];
  for (i = 1; i <= n; i++) {
    int pos1 = lower_bound(q + 1, q + 2 * n + 1, l[i] - 1) - q;
    int pos2 = lower_bound(q + 1, q + 2 * n + 1, r[i]) - q;
    cout << s[pos2] - s[pos1] << endl;
  }
  return 0;
}
