#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

struct student{
    int id;
    int grade;
};

bool Comp(student a, student b){
    if (a.grade == b.grade) {
        return a.id < b.id;
    }else {
        return a.grade < b.grade;
    }
    
};

int main() {
    int n;
    student stu[100];
    while (scanf("%d",&n) != EOF) {
        for (int i = 0; i < n; ++i) {
            scanf("%d%d",&stu[i].id,&stu[i].grade);
        }
        sort(stu, stu+n,Comp);//stu+n很重要,不然结果不对,因为比较得时候会将其他位置初始化的0也参与比较
        for (int j = 0; j < n; ++j) {
            printf("%d %d\n",stu[j].id,stu[j].grade);
        }
    }
}