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

using namespace std;

const int MAXN = 100;

struct Student {
    int id;
    int score;
};

Student arr[MAXN];

bool Compare(Student a, Student b) {
    if (a.score == b.score) {
        return a.id < b.id;
    } else {
        return a.score < b.score;
    }
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &arr[i].id, &arr[i].score);
    }
    sort(arr, arr + n, Compare);
    for(int i=0;i<n;i++){
        cout<<arr[i].id<<" "<<arr[i].score<<endl;
    }
    return 0;
}