#include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; // using mint = modint1000000007; template using vec = vector; template using pr = pair; template using mipq = priority_queue, greater>; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(i, n) for (auto i = decay_t{}; (i) < (n); ++i) #define rep2(i, l, r) for (auto i = (l); (i) < (r); ++i) #define rep3(i, l, r, d) for (auto i = (l); (i) < (r); i += (d)) #define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i, r, l) for (auto i = (r); i >= (l); --i) template bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); } template bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); } constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 60; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int T = 1; cin >> T; while (T--) solve(); } ll calc(ll n) { ll dp[10][2] = {}; dp[0][0] = 1; for (auto s : to_string(n)) { int v = s - '0'; ll ndp[10][2] = {}; rep(j, 10) rep(x, 10) { ndp[max(j, x)][1] += dp[j][1]; if (x <= v) ndp[max(j, x)][x < v] += dp[j][0]; } rep(j, 10) rep(k, 2) dp[j][k] = ndp[j][k]; } ll res = 0; rep(j, 10) rep(k, 2) res += dp[j][k] * j; return res; } void solve() { ll L, R; cin >> L >> R; cout << calc(R) - calc(L - 1) << '\n'; }