#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a[10000000] = { 0 };
void init(LL r) {
LL s = 1;
LL now = 1;
for (LL i = 1; i <= r; i++) {
a[i] = now;
now++;
if (now > s) {
s++;
now = 1;
}
a[i] += a[i - 1];
}
}
int main() {
ios::sync_with_stdio(false);
LL t;
cin >> t;
LL mu = 0;
LL l, r;
LL last = 0;
for (LL i = 0; i < t; i++) {
cin >> l >> r;
if (r > last)
init(r);
cout << a[r] - a[l - 1] << "\n";
last = r;
}
return 0;
}