#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

const long maxn = 1000000;


long phi[maxn + 10];
long gvt[maxn + 10];
long f_temp[maxn + 10];
long S1[maxn + 10];


long F[maxn + 10];             
long G_pre[maxn + 10];   
long g_val[maxn + 10];         
bool ispsf[maxn + 10];
long prF[maxn + 10], cnt_sieveF = 0;


unordered_map<long, long> cache;


void init_phi() {
    for (long i = 1; i <= maxn; i++) phi[i] = i;
    for (long i = 2; i <= maxn; i++) {
        if (phi[i] == i) {
            for (long j = i; j <= maxn; j += i) {
                phi[j] = phi[j] / i * (i - 1);
            }
        }
    }
}


void init_F() {
    for (long i = 1; i <= maxn; i++) {
        ispsf[i] = true;
    }
    ispsf[1] = false;
    F[1] = 1;
    g_val[1] = 1;
    for (long i = 2; i <= maxn; i++) {
        if (ispsf[i]) {
            prF[cnt_sieveF++] = i;
            F[i] = i + 1;
            g_val[i] = i + 1;
        }
        for (long j = 0; j < cnt_sieveF; j++) {
            long p = prF[j];
            long num = 1LL * i * p;
            if (num > maxn) break;
            ispsf[num] = false;
            if (i % p == 0) {
                g_val[num] = g_val[i] * p + 1;
                F[num] = F[i] / g_val[i] * g_val[num];
                break;
            } else {
                g_val[num] = p + 1;
                F[num] = F[i] * F[p];
            }
        }
    }
    G_pre[0] = 0;
    for (long i = 1; i <= maxn; i++) {
        G_pre[i] = G_pre[i - 1] + F[i];
    }
}


long getG(long n) {
    if (n <= 0) return 0;
    if (n <= maxn) {
        return G_pre[n];
    }
    if (cache.find(n) != cache.end()) {
        return cache[n];
    }
    long ans = 0;
    long l = 1, r;
    for (; l <= n; l = r + 1) {
        long k = n / l;
        r = n / k;
        long sum_i = (long)(l + r) * (r - l + 1) / 2;
        ans += (long)k * sum_i;
    }
    cache[n] = ans;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    
    init_phi();
    for (long i = 1; i <= maxn; i++) {
        if (i == 1) {
            gvt[i] = 1;
        } else {
            gvt[i] = (long)i * phi[i] / 2;
        }
    }
    for (long d = 1; d <= maxn; d++) {
        for (long j = d; j <= maxn; j += d) {
            f_temp[j] += gvt[d];
        }
    }
    for (long i = 1; i <= maxn; i++) {
        S1[i] = (long)i * f_temp[i];
    }

    
    init_F();

    
    vector<long> fib;
    fib.push_back(1);
    fib.push_back(1);
    while (fib.back() < 100000) {
        long next_fib = fib[fib.size() - 1] + fib[fib.size() - 2];
        fib.push_back(next_fib);
    }

    long t;
    cin >> t;
    vector<pair<long, long>> que(t);
    for (long i = 0; i < t; i++) {
        cin >> que[i].first >> que[i].second;
    }

    
    vector<long> type(t, 0);
    long cur = 0;
    long fibidx = 0;
    while (cur < t) {
        long num1 = fib[fibidx];
        long end1 = min(cur + num1, t);
        for (long i = cur; i < end1; i++) {
            type[i] = 1;
        }
        cur = end1;
        if (cur < t) {
            type[cur] = 2;
            cur++;
        }
        fibidx++;
    }

    
    for (long i = 0; i < t; i++) {
        long x = que[i].first;
        long y = que[i].second;
        if (type[i] == 1) {
            long ans = S1[y] - S1[x];
            cout << ans << '\n';
        } else {
            long res = getG(y) - getG(x - 1);
            long ans = (long)res;
            cout << ans << '\n';
        }
    }

    return 0;
}