#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
bool cmp(const pair<string,int> &a,const pair<string,int> &b)
{
if (a.second==b.second)
return a.first>b.first;
return a.second<b.second;
}
int main()
{
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
vector<pair<string,int> > v;
for (int i=0; i<n; i++)
{
string s;
int num,flag=0;
cin>>s>>num;
for (int i=0; i<v.size(); i++)
if (v[i].first==s)
{
v[i].second+=num;
flag=1;
break;
}
if (!flag)
v.pb(mp(s,num));
}
sort(v.begin(),v.end(),cmp);
cout<<v[v.size()-1].first<<" "<<v[v.size()-1].second<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCmJvb2wgY21wKGNvbnN0IHBhaXI8c3RyaW5nLGludD4gJmEsY29uc3QgcGFpcjxzdHJpbmcsaW50PiAmYikKewoJaWYgKGEuc2Vjb25kPT1iLnNlY29uZCkKCQlyZXR1cm4gYS5maXJzdD5iLmZpcnN0OwoJcmV0dXJuIGEuc2Vjb25kPGIuc2Vjb25kOwp9CmludCBtYWluKCkKewoJaW50IHQ7CgljaW4+PnQ7Cgl3aGlsZSAodC0tKQoJewoJCWludCBuOwoJCWNpbj4+bjsKCQl2ZWN0b3I8cGFpcjxzdHJpbmcsaW50PiA+IHY7CgkJZm9yIChpbnQgaT0wOyBpPG47IGkrKykKCQl7CgkJCXN0cmluZyBzOwoJCQlpbnQgbnVtLGZsYWc9MDsKCQkJY2luPj5zPj5udW07CgkJCWZvciAoaW50IGk9MDsgaTx2LnNpemUoKTsgaSsrKQoJCQkJaWYgKHZbaV0uZmlyc3Q9PXMpCgkJCQl7CgkJCQkJdltpXS5zZWNvbmQrPW51bTsKCQkJCQlmbGFnPTE7CgkJCQkJYnJlYWs7CgkJCQl9CgkJCWlmICghZmxhZykKCQkJCXYucGIobXAocyxudW0pKTsKCQl9CgkJc29ydCh2LmJlZ2luKCksdi5lbmQoKSxjbXApOwoJCWNvdXQ8PHZbdi5zaXplKCktMV0uZmlyc3Q8PCIgIjw8dlt2LnNpemUoKS0xXS5zZWNvbmQ8PGVuZGw7Cgl9CglyZXR1cm4gMDsKfQ==