#include<stdio.h>
#include<stdlib.h>
struct a{
char s[25];
int d,b,c;
};
int comp(const void *p,const void *q){
return ((struct a *)q)->c-((struct a *)p)->c;
}
int main(){
struct a q[108];
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s %d %d",q[i].s,&q[i].d,&q[i].b);
q[i].c=q[i].d+q[i].b;
}
qsort(q,n,sizeof(struct a),comp);
for(int i=0;i<n;++i){
printf("%s\n",q[i].s);
}
}
}