#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll l, r; cin >> l >> r; auto f = [&](ll v){ string s = to_string(v); array,2> dp{}; dp[1][0] = 1; for(auto c : s){ array,2> ndp{}; for(int i = 0; i < 2; i++){ int r = i ? c - '0' : 9; for(int j = 0; j < 10; j++){ for(int k = 0; k <= r; k++){ ndp[i & (k == r)][max(j, k)] += dp[i][j]; } } } dp = ndp; } ll res = 0; for(int i = 1; i < 10; i++) res += i * (dp[0][i] + dp[1][i]); return res; }; cout << f(r) - f(l - 1) << '\n'; } }