#include<iostream>
#include<algorithm>
using namespace std;
typedef struct Student {
string name;
int total;
} student;
student st[105];
bool cmpare(const student &a, const student &b) {
return a.total > b.total;
}
int main() {
int T,N,t1,t2;
cin>>T;
while(T--) {
cin>>N;
for(int i=0; i<N; i++) {
cin>>st[i].name>>t1>>t2;
st[i].total=t1+t2;
}
sort(st, st + N, cmpare);
for(int i=0; i<N; i++) {
cout<<st[i].name<<endl;
}
}
return 0;
}