#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#define maxn 1010
using namespace std;

typedef struct Stu{
    string name;
    int age;
    int score;
}S;

S s[maxn];


bool cmp(S s1,S s2)
{
    if(s1.score != s2.score)return s1.score<s2.score;
    else if(s1.name!=s2.name)return s1.name < s2.name;
    else return s1.age<s2.age;
}

int main() {
    int N;
    while(cin>>N)
    {
        for(int i=0;i<N;i++)
        {
            cin>>s[i].name>>s[i].age>>s[i].score;
        }
        sort(s,s+N,cmp);
        for(int i=0;i<N;i++){
            cout<<s[i].name<<" "<<s[i].age<<" "<<s[i].score<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")