#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct node{
int key;
string s;
bool operator<(node n1)const{
return key>n1.key;
}
node(int kk,string ss){
key=kk;
s=ss;
}
};
priority_queue<node>q;
int main(){
int n,key;
string s;
cin>>n;
for(int i=0;i<n;i++){
cin>>key>>s;
q.push(node(key,s));
}
while(!q.empty()){
node e=q.top();
q.pop();
cout<<e.key<<" "<<e.s<<endl;
}
return 0;
}
#include<queue>
#include<string>
using namespace std;
struct node{
int key;
string s;
bool operator<(node n1)const{
return key>n1.key;
}
node(int kk,string ss){
key=kk;
s=ss;
}
};
priority_queue<node>q;
int main(){
int n,key;
string s;
cin>>n;
for(int i=0;i<n;i++){
cin>>key>>s;
q.push(node(key,s));
}
while(!q.empty()){
node e=q.top();
q.pop();
cout<<e.key<<" "<<e.s<<endl;
}
return 0;
}