#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <unordered_set>

using namespace std;

#define pii pair<int,int>
#define pll pair<long long, long long>

int main(){


  int ncases;
  cin >> ncases;
  for(int z = 0; z < ncases; z++){
  
    long long l, r;
    long long ret = 0;
    cin >> l >> r;
    long long maxx = (r - 2 * l + 1);
    if(maxx > 0){
      ret = maxx * (maxx + 1) / 2;
    }
  
    cout << ret << endl;
  }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; (i) < n ; i++)


using namespace std;
using ll = long long;

ll result(ll a, ll b){
    ll v = b - 2 * a + 1;
    ll u = v * (v + 1)/2;
    return u;
}
int main(){
    int T; cin >> T;

    ll outc[T];
    rep(i,T){

        ll l, r ; cin >> l >> r;
        if (r >= 2 * l){
            ll c = result(l,r);
            outc[i] = c;

        } else {
            outc[i] = 0;
        }

    }

    rep(i,T){
        cout << outc[i] << endl;
    }
    return 0;
}