#include<stdio.h>
struct a{
char name[20];
int x;
int y;
};
int main(void)
{
struct a yh[101];
struct a zy;
int t,z,x,c,v,b;
b=0;b++;
scanf("%d",&t);
while(t--)
{
int i,j;
scanf("%d",&z);
for(x=0;x<z;x++)
{
scanf("%s%d%d",yh[x].name,&yh[x].x,&yh[x].y);
}
for(i=1;i<z;i++)
{
for(j=0;j<z-i;j++)
{
if((yh[j].x+yh[j].y)>(yh[j+1].x+yh[j+1].y))
{
zy=yh[j];
yh[j]=yh[j+1];
yh[j+1]=zy;
}
}
}
for(i=z-1;i>=0;i--)
{
printf("%s\n",yh[i].name);
}
}
return 0;
}