#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int T;
	cin>>T;
	while(T--) {
		int l,r;
		cin>>l>>r;
		if(2*l>r) {
			cout<<"0\n";
			continue;
		}
		cout<<(r-2*l+1)*(r-2*l+2)/2<<"\n";
	}
}
#include <iostream>
#include <algorithm>
int n, a[1000], b[1000];
int main() {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i] >> b[i];
  int ans = 1001001001;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) {
        ans = std::min(ans, a[i] + b[j]);
      } else {
        ans = std::min(ans, std::max(a[i], b[j]));
      }
    }
  }
  std::cout << ans << '\n';
}