		#include<bits/stdc++.h>
using namespace std ;
 
#define int              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (int)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<int,int> 
#define pii             pair<int,int>
#define ld              long double
#define bug(x) cerr<<"#x"<<" is "<<x<<endl;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
 
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}
int tError()
{
    int l,r;
    cin>>l>>r;
    if(l==0 && r==0)
    	return cout<<1<<endl,0;
    else if((l==r)or(r-2*l+1<=0))
    	return cout<<0<<endl,0;
    
    int ans=(r-2*l)+1;
    int anss=(ans*(ans+1))/2;
    cout<<anss<<endl;
    return 0;
}
 
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // #ifndef ONLINE_JUDGE
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  //  #endif

    int TESTS=1;
    cin>>TESTS;
    while(TESTS--)
        tError();
        
    //    cerr << "Time taken: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    return 0;
}
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, a[1000], b[1000];
    cin>>n;
    for (int j = 0; j < n; j++)
    cin>>a[j]>>b[j];
    int min = a[0], mini = 0;
    for (int i = 1; i < n; i++)
    {
        if(a[i]<min)
        {
            min = a[i];
            mini = i;
        }
    }
    b[mini] = a[mini]+b[mini];
    int mi = b[0], mii = 0;
    for (int k = 1; k < n; k++)
    {
        if(b[k]<mi)
        {
            mi = b[k];
            mii = k;
        }
    }
    if(mini==mii)cout<<b[mii];
    else
    printf("%d", max(a[mini], b[mii]));
    return 0;
}