#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(998244353);

vector<ll> ret;

int t, l, r;

int main(void) {
	cin >> t;
	ll n = 0;
	for (int i = 0; i < t; i++) {
		cin >> l >> r;

		n = r - l;
		if (l <= n) {
			n -= l - 1;
			ret.push_back(n * (n + 1) / 2);
		}

		else
			ret.push_back(0);
	}

	for (int i = 0; i < t; i++)
		cout << ret[i] << endl;
	return 0;
}
#include<bits/stdc++.h>
using namespace  std;
 
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define ll           long long  
#define int          long long
#define vi           std::vector<int>
#define setbits(x)   __builtin_popcountll(x)
#define pb           push_back
#define fn           for(int i=0;i<n;i++)
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define all(x)       x.begin(), x.end()
#define  ret(x) {cout << #x << endl; return;}
#define PI           3.14159265358979323846
#define pii          pair<ll,ll>
#define fr           first
#define sc           second
 
const int mod = 1e9+7;
void getio();
ll ceill(ll a, ll b) { return (a + b - 1) / b; }

int ans[1000001];
void solve()
{
    int l, r;
    cin >> l >> r;
    int use = r-2*l;
    int ans = 0;
    // cout << "use " << use << endl;
    if(use<0) ret(0)
    // if(use==0) ret(1)
    if(use%2)
    {
        int n = (use+1)/2;
        int sum = (n * (2*1 + (n-1) * 2)) / 2;
        ans = sum*2 + n;
    }
    else 
    {
        int n = use/2 + 1;
        int sum = n * (n-1);
        ans = sum * 2 + n;
    }
    cout << ans << endl;
}
 
 
int32_t main()
{   
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    getio();
    int t; cin >> t; while (t--)
    solve();
}
 
void getio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}