#include <stdio.h>
#include <stdlib.h>
struct stu {
int x;
int y;
char name[50];
int total;
};
int comp(const void *p,const void *q){
return ((struct stu *)q)->total-((struct stu *)p)->total;
}
int main ()
{
int t;
scanf("%d",&t);
int n,i=0;
struct stu chengji[100];
while(t--){
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s %d %d",&chengji[i].name,&chengji[i].x,&chengji[i].y);
chengji[i].total=chengji[i].x+chengji[i].y;
}
qsort(chengji,n,sizeof(struct stu),comp);
for(i=0;i<n;i++){
printf("%s\n",chengji[i].name);
}
}
}