#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 500010, mod = 998244353;

int a[3];


int main() {

    string s1, s2;
    int d1 = 0, d2 = 0;
    int n;
    cin >> n;
    while (n --) {
        string s;
        int h;
        cin >> s >> h;
        if(h >= d1) d2 = d1, s2 = s1, d1 = h, s1 = s;
        else if (h > d2)    d2 = h, s2 = s;
    }
    cout << s2 << endl;


    return 0;
}

#define LOCAL0
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define debug(msg) cout << (msg) << endl
#define FOR(i, a, b) for (ll i=a; i<=(b); i++)
#define ROF(i, a, b) for (ll i=a; i>=(b); i--)
#define pb(x) push_back(x) 
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define sz(x) (ll)x.size()
#define JUDGE(x) if(x) cout << "Yes\n"; else cout << "No\n";
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
	#endif
	int T;
	cin >> T;
	while(T--){
		ll l, r;
		cin >> l >> r;
		if(r-l<l) cout << 0 << endl;
		else cout << (r-l+1)*(r-2*l+2)-(r-2*l+2)*(r+1)/2 << endl;;
	}
    return 0;
}