#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class person{
    public:
        int score;
        string name;
        int age;
    person(int s,string n,int a){
        score = s;
        name=n;
        age=a;
    }
    void say(){
        cout<<name<<" "<<age<<" "<<score<<endl;
    }
};
bool cmp(person p1, person p2){
    if(p1.score!=p2.score)return p1.score<p2.score;
    if(p1.name!=p2.name)return p1.name<p2.name;
    return p1.age < p2.age;
}
int main() {
    int n;cin>>n;
    string name; int age,score;
    vector<person>v;
    for(int i =0;i<n;i++){
        cin>>name>>age>>score;
        person p(score,name,age);
        v.push_back(p);
    }
    sort(v.begin(),v.end(),cmp);
    for(auto a:v)
        a.say();
}
// 64 位输出请用 printf("%lld")