#include<iostream>
#include<algorithm>
using namespace std;
const int N=100;
struct student
{
string name;
int score;
bool operator <(const student & t)const
{
return score > t.score;//降序排列
}
}s[N];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>s[i].name>>s[i].score;
}
sort(s,s+n);
for(int i=0;i<n;i++)
{
cout<<s[i].name<<" "<<s[i].score<<endl;
}
return 0;
}