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

using namespace std;

const int MAX_NUM = 100;

struct Student {
    int number;
    int score;
};


/**
 * 自定义比较规则,升序排序
 * @param x
 * @param y
 * @return
 */
bool compare(Student x, Student y) {
    //成绩相等,则比较学号
    if (x.score == y.score) {
        return x.number < y.number;
    } else {
        //成绩不等,则比较成绩
        return x.score < y.score;
    }
}

/**
 * 成绩排序--清华大学
 * @return
 */
int main() {
    Student studentArr[MAX_NUM];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> studentArr[i].number >> studentArr[i].score;
    }

    sort(studentArr, studentArr + n, compare);

    for (int j = 0; j < n; ++j) {
        cout << studentArr[j].number << " " << studentArr[j].score << endl;
    }

    return 0;
}