#include<bits/stdc++.h>
using namespace std;
struct wsl{
int hs;
string xm;
int fs;
}a[200];
bool cmp(wsl x,wsl y){
if(x.fs>y.fs||(x.fs==y.fs&&x.hs<y.hs))return true;
else return false;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].hs>>a[i].xm>>a[i].fs;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].hs<<" "<<a[i].xm<<" "<<a[i].fs<<endl;
}
return 0;
}
/**************************************************************
Problem: 1414
User: wangsenlin
Language: C++
Result: Accepted
Time:12 ms
Memory:2100 kb
****************************************************************/