#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
//定义学生结构体
struct Student {
int number;
int score;
Student() {}
Student(int n,int s):number(n),score(s) {}
};
//定义数组保存比较学生的基本信息
Student arr[100];
//定义比较函数
bool Compare(Student s1,Student s2) {
//成绩相同比学号
if(s1.score == s2.score) {
return s1.number < s2.number; //'<',指按照比较的参数由小到大排序
}else{
return s1.score < s2.score; ////'<',指按照比较的参数由小到大排序,同理,如果是'>',指按照由大到小排序
}
}
int main() {
int n;
scanf("%d",&n);
for(int i = 0; i < n; ++i) {
scanf("%d%d",&arr[i].number,&arr[i].score);
}
sort(arr,arr + n,Compare);
for(int i = 0; i < n; ++i) {
printf("%d %d\n",arr[i].number,arr[i].score);
}
return 0;
}