#include<stdio.h>
#include<string.h>
struct STUDENT
{
char a[100];
int b;
int c;
};
int main()
{
int n,i,j,t;
struct STUDENT S[1000];
struct STUDENT axi;
memset(S,0,1000);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s %d %d",&S[i].a,&S[i].b,&S[i].c);
for(i=0;i<n;i++)
for(j=0;j<n-1-i;j++)
{
if(S[j].c>S[j+1].c||(S[j].c==S[j+1].c&&S[j].a[0]>S[j+1].a[0])||(S[j].c==S[j+1].c&&S[j].a[0]==S[j+1].a[0]&&S[j].b>S[j+1].b))
{
axi=S[j];
S[j]=S[j+1];
S[j+1]=axi;
}
}
for(i=0;i<n;i++)
printf("%s %d %d\n",S[i].a,S[i].b,S[i].c);
return 0;
}