#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef struct student{
    int p;//学号
    int q;//成绩
}stu; 
bool comp(stu a,stu b){
    if(a.q==b.q){//学生的成绩相同,则按照学号的大小进行从小到大排序。
        return a.p<b.p;
    }
    else return a.q<b.q;//成绩不同,按照学生的成绩从小到大进行排序
}
int main() {
    int N; 
     stu a[101];
    while (scanf("%d",&N)!=EOF) {  
        for(int i=0;i<N;i++){
            scanf("%d %d",&a[i].p,&a[i].q);
        }
        sort(a, a+N, comp);
    
    for(int i=0;i<N;i++){
            printf("%d %d\n",a[i].p,a[i].q);

        }
}}
// 64 位输出请用 printf("%lld")