#include<stdio.h>
struct people
{
char name[31];
int ll,sj,zf;
};
int main()
{
struct people p[101],n;
int a,b;
scanf("%d",&a);
for(int i=0;i<a;i++)
{
scanf("%d",&b);
for(int j=0;j<b;j++){scanf("%s%d%d",p[j].name,&p[j].ll,&p[j].sj);p[j].zf=p[j].ll+p[j].sj;}
for(int j=0;j<b-1;j++)
{
for(int m=j+1;m<b;m++)
{
if(p[j].zf<p[m].zf){n=p[j];p[j]=p[m];p[m]=n;}
}
}
for(int j=0;j<b;j++)printf("%s\n",p[j].name);
}
return 0;
}