#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

struct Student{
    int number;
    int score;
};

Student arr[100];

bool compare(Student x ,Student y){
    if (x.score == y.score){
        return x.number <y.number;
    }
    else{
        return x.score < y.score;
    }
}

int main(){
    int n;
    scanf("%d",&n);
    for (int i = 0;i<n;i++){
        int p,q;
        scanf("%d %d ",&p,&q);
        arr[i].number=p;
        arr[i].score=q;
    }
    sort(arr,arr+n,compare);

    for (int i = 0;i<n;i++){
        printf("%d %d\n",arr[i].number,arr[i].score);
    }
    return 0;
}