#include <bits/stdc++.h>

using namespace std;

struct Student{
	int num;
	int score;
}stu[20];

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

int main(){
	int n;

	cin >> n;
	
	for(int i = 0;i < n;i ++)cin >> stu[i].num >> stu[i].score;
	
	sort(stu,stu + n,cmp);
	
	for(int i = 0;i < n;i ++)cout << stu[i].num << " " << stu[i].score <<endl;
	
	return 0;
}