#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main(){
    int n;
    cin>>n;
    int a[n];
    int b[n];

    ll ans = 100000000000000 ;

    for(int i = 0 ; i < n ; i++){
        cin>>a[i]>>b[i];
        ll ch = a[i]+b[i] ;
        ans = min(ans,ch);
    }

    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(i == j) continue ;
            ll ch = max(a[i],b[j]) ;
            // cout<<ch<<endl;
            ans = min(ans , ch);
        }
    }

    cout<<ans<<endl;
}
#include <bits/stdc++.h>
 
using namespace std;
 
// a + (a+1) + ... + b
long sum(const long &a, const long &b) { return (a + b) * (b - a + 1) / 2; }
 
int main() {
  int T;
  cin >> T;
  while (T--) {
    long L, R;
    cin >> L >> R;
    const long minC = L;
    const long maxC = R - L;
    if (minC > maxC) {
      cout << 0 << endl;
    } else {
      cout << sum(R - maxC - L + 1, R - minC - L + 1) << endl;
    }
  }
  return 0;
}