#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct student{
    int number;
    int score;
};
bool compare(student x,student y){
    if (x.score==y.score) {
        return x.number<y.number;
    }else {
        return x.score<y.score;
    }
}
vector<student> sortStudent(vector<student> stu){
    sort(stu.begin(),stu.end(),compare);
    return stu;
}
int main() {
    int n;
    cin>>n;
    vector<student> stu(n);
    for(int i=0;i<n;i++){
        cin>>stu[i].number;
        cin>>stu[i].score;
    }
    for(auto i :sortStudent(stu))
        cout<<i.number<<" "<<i.score<<endl;
}