#include<iostream>
#include<queue>
#include<string>
using namespace std;

struct stu{
    string name;
    int age;
    int grade;
    stu(string s,int a,int g):name(s),age(a),grade(g){}
    bool operator<(const stu& student)const{
        if(grade==student.grade && name==student.name)
            return age>student.age;
        else if(grade==student.grade)
            return name>student.name;
        return grade>student.grade;
    }
};

int main(){
    int n;
    while(cin>>n){
        string name;
        int age,grade;
        priority_queue<stu> pq;
        for(int i=0;i<n;i++){
            cin>>name>>age>>grade;
            pq.push(stu(name,age,grade));
        }
        while(pq.size()){
            cout<<pq.top().name<<" "<<pq.top().age<<" "<<pq.top().grade<<endl;
            pq.pop();
        }
    }
    return 0;
}