#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define mod 1000000007

// templates
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x, y) fixed << setprecision(y) << x
#define ss(s) scanf(" %[^\n]%*c", s)
#define sc(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define ps(s) printf("%s\n", s)
#define pr(n) printf("%d\n", n)
#define pl(n) printf("%lld\n", n)
#define prs(n) printf("%d ", n)
#define pls(n) printf("%lld ", n)
using namespace std;

const ll inf = (ll)1e15 + 10;
const int N = (int)1e6 + 10;

void solve() {
  int n;
  cin >> n;
  vector<pair<int, string>> a;
  for (int i = 0; i < n; i++) {
    int d;
    string s;
    cin >> s >> d;
    a.push_back({d, s});
  }
  sort(all(a));
  cout << a[n - 2].S << endl;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
  int t = 1;
  // sc(t);
  while (t--) {
    solve();
  }
  //	cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
  return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,L,R;
signed main(){
	cin>>T;
	while(T--){
		cin>>L>>R;
		if(R>=2*L)printf("%lld\n",(R-2*L+2)*(R-2*L+1)/2);
		else printf("0\n");
	}
	return 0;
}
/*

*/