#include #include using namespace std; using i32 = int; using i64 = long long; using i128 = __int128_t; using f64 = double; using p2 = pair; using p3 = tuple; using mint = atcoder::modint998244353; constexpr i64 inf = 1e18; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 solve(i64 n) { if (n == 0) return 0; vector v; while (n > 0) v.push_back(n % 10), n /= 10; reverse(v.begin(), v.end()); vector dp(10, 0); i64 mx = 0; for (i64 i = 0; i < v.size(); i++) { vector ndp(10, 0); for (i64 j = 0; j < 10; j++) for (i64 k = 0; k < 10; k++) { ndp[max(j, k)] += dp[j]; } // for (i64 x : ndp) cout << x << " "; // cout << "!\n"; if (i != 0) { for (i64 j = 0; j < v[i]; j++) ndp[max(j, mx)]++; for (i64 j = 1; j < 10; j++) ndp[j]++; } else { for (i64 j = 1; j < v[i]; j++) ndp[max(j, mx)]++; } mx = max(mx, v[i]); swap(dp, ndp); // for (i64 x : dp) cout << x << " "; // cout << "!\n"; } i64 ans = 0; for (i64 i = 0; i < 10; i++) ans += dp[i] * i; // for (i64 x : v) cout << x; // cout << ": " << ans << "\n"; return ans; } void _main() { i64 tt; cin >> tt; for (;tt--;) { i64 l, r; cin >> l >> r; r++; i64 ans = solve(r) - solve(l); cout << ans << "\n"; } }