#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define maxm 600005 
#define maxn 200005 
#define ls (tot << 1)
#define rs (tot << 1 | 1)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const double pi = acos(-1);
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;char ch = getchar();
    while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
    return x * f;
}

int t, l, r;
ll ans;

int main(){
	int i, j, x;
	t = read();
	while(t--){
		l = read(), r = read();
		ans = 0;
		ans += 1ll * (r + 1) * (r + 2) / 2;
		if(l){
			ans -= 1ll * l * (r + 1 + r - l + 2);
			ans += 1ll * l  * l;
			if(r < 2 * l - 2) ans -= 1ll * (l - 1 - (r - l + 2) + 1 + 1) * (l - 1 - (r - l + 2) + 1) / 2;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
long long ans=0, first, last, num;
int l, r, n;
int main() {
    cin>>n;
    while(n--) {
        ans=0;
        cin>>l>>r;
        if(l==r && l==0) cout<<1<<endl;
        else if(l+l>r) cout<<0<<endl;
        else {
            first=l+l;
            last=r;
            num=last-first+1;
            ans=1LL*(1+num)*num/2;
            cout<<ans<<endl;
        }
    }
 
    return 0;
}
/*
5
2 6
0 0
1000000 1000000
12345 67890
0 1000000
 
6
1
0
933184801
500001500001
 
 
 
 
*/