#include <iostream>
#include <string>
using namespace std;
long long countPrefix(long long x) {
    if (x < 0) return 0;
    long long dp[4][2]{}; dp[0][1] = 1;
    for (char ch : to_string(x)) {
        long long next[4][2]{}; int bound = ch - '0';
        for (int used = 0; used <= 3; ++used) for (int tight = 0; tight <= 1; ++tight)
            for (int digit = 0; digit <= (tight ? bound : 9); ++digit) {
                int count = used + (digit != 0);
                if (count <= 3) next[count][tight && digit == bound] += dp[used][tight];
            }
        for (int u = 0; u <= 3; ++u) for (int t = 0; t < 2; ++t) dp[u][t] = next[u][t];
    }
    long long answer = 0;
    for (auto& row : dp) for (long long v : row) answer += v;
    return answer;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t; if (!(cin >> t)) return 0;
    while (t--) { long long l, r; cin >> l >> r; cout << countPrefix(r) - countPrefix(l - 1) << '\n'; }
}
