#include<iostream> #include<algorithm> using namespace std; const int N = 110; struct Stu { int id; int score; } s[N]; bool cmp(Stu s1, Stu s2) { if (s1.score == s2.score) return s1.id < s2.id; return s1.score < s2.score; } int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i].id >> s[i].score; } sort(s, s + n, cmp); for (int i = 0; i < n; i++) { printf("%d %d\n", s[i].id, s[i].score); } return 0; }