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

const int N=110;
struct stu{
    int num;
    int grade;
    bool operator< (const stu &t) const{
        if(grade==t.grade) return num<t.num;
        return grade<t.grade;//按成绩升序
    }
}a[N];
int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int p,q;
        cin>>p>>q;
        stu s={p,q};
        a[i]=s;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        cout<<a[i].num<<" "<<a[i].grade<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")