#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
using namespace std;
//#pragma GCC optimize("Ofast")
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define lcin(x) ll x; cin >> x;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;






int main(){
    ll N;
    cin >> N;
    vs S(N);
    vll T(N);
    rep(i,N){
        cin >> S.at(i);
        cin >> T.at(i);
    }
    ll ma = 0;
    ll ma2 = 0;
    ll ma2in = -1;
    ll main = -1;
    rep(i,N){
        if(T.at(i) > ma){
            ma2in = main;
            main = i;
            ma2 = ma;
            ma = T.at(i);
        }else{
            if(T.at(i) > ma2){
                ma2in = i;
                ma2 = T.at(i);
            }
        }
    }
    cout << S.at(ma2in) << endl;


    return 0;
}




#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT  = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL   = std::numeric_limits<long long>::max();

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////

struct mint {
    static const int mod = 1000000007;
    long long x; // typedef long long ll;
    mint(long long x = 0) :x((x%mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x; }
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x; }

void countNb(ll& res) {
    ll n, a, b; cin >> n >> a >> b;

    // ensure A <= B
    if (b < a) {
        ll tmp = a;
        a = b;
        b = tmp;
    }

    mint N(n), A(a), B(b);

    mint nbA = N - (A - 1); nbA = nbA * nbA;
    mint nbB = N - (B - 1); nbB = nbB * nbB;
    mint nbtotal = nbA * nbB;

    // dupulication: inside
    mint nbAb = B - (A - 1); nbAb = nbAb * nbAb;
    mint nbInside = nbAb * nbB;

    // cross
    mint cnt = 0;
    for (ll alpha = 1; alpha < a; ++alpha) {
        mint Alpha(alpha);
        mint nbCross = (B - A + Alpha * 2) * 4;
        mint nbIn = N - (B + Alpha - 1); nbIn = nbIn * nbIn;
        cnt += nbCross * nbIn;
    }

    mint count = nbtotal - nbInside - cnt;
    res = count.x;
}

void countNb2(ll& res) {
    mint N, A, B; cin >> N >> A >> B;
    ll nbSpace = N.x - A.x - B.x;
    mint x3 = (nbSpace >= 0) ? (N-A-B+2)*(N-A-B+1) : 0;
    mint x2 = (N-A+1)*(N-B+1) - x3;
    mint x1 = x2 * x2;
    mint total = (N-A+1)*(N-B+1) * (N-A+1)*(N-B+1);
    mint ans = total - x1;
    res = ans.x;
}


void Main() {
    ll T; cin >> T;
    vector<ll> res(T);
    for (ll i = 0; i < T; ++i) {
        countNb2(res[i]);
    }

    rep(i, T) {
        cout << res[i] << endl;
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}
