#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
long long dp[20][4];
int a[20];
long long dfs(int pos, int sta, bool limit) {
  if (pos == -1) return 1;
  if (!limit && dp[pos][3 - sta] != 0) return dp[pos][3 - sta];
  int up = limit ? a[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    if (sta == 3) {
      if (i == 0) ans += dfs(pos - 1, sta, limit && i == a[pos]);
    } else {
      if (i == 0)
        ans += dfs(pos - 1, sta, limit && i == a[pos]);
      else
        ans += dfs(pos - 1, sta + 1, limit && i == a[pos]);
    }
  }
  if (!limit && sta) dp[pos][3 - sta] = ans;
  return ans;
}
long long solve(long long x) {
  int cnt = 0;
  while (x) {
    a[cnt++] = x % 10;
    x /= 10;
  }
  return dfs(cnt - 1, 0, true);
}
int main() {
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << solve(r) - solve(l - 1) << endl;
  }
  return 0;
}
