#include<stdio.h>
struct aaa{
char mz[30];
int ll,sj,tt;
}q[100],w;
int main(){
int n;
scanf("%d",&n);
while(n--){
int a,b,c;
scanf("%d",&a);
for(b=0;b<a;b++){
scanf("%s %d %d",q[b].mz,&q[b].ll,&q[b].sj);
q[b].tt=q[b].ll+q[b].sj;
}
for(b=1;b<a;b++){
for(c=a-1;c>=b;c--){
if(q[c].tt>q[c-1].tt){
w=q[c];
q[c]=q[c-1];
q[c-1]=w;
}
}
}
for(b=0;b<a;b++){
printf("%s\n",q[b].mz);
}
}
return 0;
}