#include <iostream>
#include <algorithm>
using namespace std;
typedef struct student{
int id,pt;
}student;
bool compare(student a,student b){
if(a.pt==b.pt){
return a.id<b.id;
}
return a.pt<b.pt;
}
student s[100];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&s[i].id,&s[i].pt);
}
sort(s,s+n,compare);
for(int i=0;i<n;i++){
printf("%d %d\n",s[i].id,s[i].pt);
}
return 0;
}