#include<iostream>
#include<algorithm>
using namespace std;
struct student{
int number;
int grade;
bool operator < (student stu){ //小于号运算符重载
if(grade==stu.grade)return number<stu.number;
else return grade<stu.grade;
}
};
student ss[101];
int main(){
int n;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>ss[i].number>>ss[i].grade;
}
sort(ss,ss+n);
for(int i=0;i<n;i++){
cout<<ss[i].number<<" "<<ss[i].grade<<endl;
}
}
return 0;
}
#include<algorithm>
using namespace std;
struct student{
int number;
int grade;
bool operator < (student stu){ //小于号运算符重载
if(grade==stu.grade)return number<stu.number;
else return grade<stu.grade;
}
};
student ss[101];
int main(){
int n;
while(cin>>n){
for(int i=0;i<n;i++){
cin>>ss[i].number>>ss[i].grade;
}
sort(ss,ss+n);
for(int i=0;i<n;i++){
cout<<ss[i].number<<" "<<ss[i].grade<<endl;
}
}
return 0;
}