#include<bits/stdc++.h>
using namespace std;


struct Student{

    string name;
    int age;
    int score;
};

bool cmp(Student a,Student b)
{
    if(a.score!=b.score)
    {
        return a.score<b.score;
    }
    else if(a.name!=b.name)
    {
        return a.name<b.name;
    }
    else {
        return a.age<b.age;
    }
    
}

int main()
{
    int n;
    while(cin>>n)
    {
        vector<Student> students(n);
        vector<Student>::iterator it;

        for(int i = 0;i<n;i++)
        {
            cin>>students[i].name>>students[i].age>>students[i].score;
        }

        sort(students.begin(),students.end(),cmp);
        for(it = students.begin();it != students.end();it++)
        {
            cout<<(*it).name<<" "<<(*it).age<<" "<<(*it).score<<endl;
        }
    }

    return 0;
}