#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &a,const pair<int,int> &b)
{
if(a.first>b.first)
return a.first>b.first;
else if(a.first<b.first)
return a.first<b.first;
else
{
return a.second<b.second;
}
}
map<pair<int,int>,string>m;
int main()
{
int n,t;
cin>>t;
while(t--)
{
int a,b;
cin>>n;
pair<int,int>p[100];string s;
for(int i=0;i<n;++i)
{
cin>>s;
cin>>a>>b;
p[i].first=a;p[i].second=b;
m[p[i]]=s;
}
sort(p,p+n,comp);
cout<<m[p[0]]<<"\n";m.clear();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgICAgICAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAgICAgICBib29sIGNvbXAoY29uc3QgcGFpcjxpbnQsaW50PiAmYSxjb25zdCBwYWlyPGludCxpbnQ+ICZiKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYS5maXJzdD5iLmZpcnN0KQogICAgICAgICAgICAgICAgcmV0dXJuIGEuZmlyc3Q+Yi5maXJzdDsKICAgICAgICAgICAgZWxzZSBpZihhLmZpcnN0PGIuZmlyc3QpCiAgICAgICAgICAgICAgICByZXR1cm4gYS5maXJzdDxiLmZpcnN0OwogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHJldHVybiBhLnNlY29uZDxiLnNlY29uZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbWFwPHBhaXI8aW50LGludD4sc3RyaW5nPm07CgogICAgICAgIGludCBtYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIAoKICAgICAgICAgICBpbnQgbix0OwogICAgICAgICAgIGNpbj4+dDsKICAgICAgICAgICB3aGlsZSh0LS0pCiAgICAgICAgICAgewogICAgICAgICAgICAgICBpbnQgYSxiOwogICAgICAgICAgICAgICBjaW4+Pm47CiAgICAgICAgICAgICAgIHBhaXI8aW50LGludD5wWzEwMF07c3RyaW5nIHM7CiAgICAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bjsrK2kpCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgIGNpbj4+czsKICAgICAgICAgICAgICAgICAgIGNpbj4+YT4+YjsKICAgICAgICAgICAgICAgICAgIHBbaV0uZmlyc3Q9YTtwW2ldLnNlY29uZD1iOwogICAgICAgICAgICAgICAgICAgbVtwW2ldXT1zOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIHNvcnQocCxwK24sY29tcCk7CiAgICAgICAgICAgICAgIGNvdXQ8PG1bcFswXV08PCJcbiI7bS5jbGVhcigpOwoKCiAgICAgICAgICAgfQoKCiAgICAgICAgICAgICAgICAgcmV0dXJuIDA7CgoKICAgICAgICB9Cg==