#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.cj>y.cj||(x.cj==y.cj&&x.cj<y.cj))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;
}
}
	return 0;
}

/**************************************************************
	Problem: 1414
	User: wangsenlin
	Language: C++
	Result: Compile Error
****************************************************************/