#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl
#define left    __left
#define right   __right
#define prev    __prev
#define fi      first
#define se      second
template <class X, class Y>
    bool maximize(X &x, Y y) {
        if (x < y) return x = y, true;
        else return false;
    }
template <class X, class Y>
    bool minimize(X &x, Y y) {
        if (x > y) return x = y, true;
        else return false;
    }
int query;
ll L, R;
ll remain(ll x) {
    int res = x % 9;
    if (res == 0) res = 9;
    return res;
}
int calc(int l, int r) {
    if (l > r) return 0;
    return (r + l) * (r - l + 1) / 2;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    // freopen("test.inp","r",stdin);
    // freopen("test.out","w",stdout);
    cin >> query;
    while (query--) {
        cin >> L >> R;
        if (R - L <= 30) {
            int ans = 0;
            while (L <= R) {
                ans += remain(L);
                ++L;
            }
            cout << ans << "\n";
        } else {
            ll ans = 0;
            int remL = remain(L);
            int remR = remain(R);
            ans += calc(remL, 9);
            ans += calc(1, remR);
            L += 9 - remL + 1;
            R -= remR;
//            ans += (R - L + 1) / 9 * 45;
            ans += (R - L + 1) * 5;
            cout << ans << "\n";
        }
    }
    return 0;
}
/* Discipline - Calm */
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |