#include <stdio.h>
#include <stdlib.h>

struct student
{
	int number;
	int score;
};

int main()
{
	struct student students[101];
	int n, i, j;
	struct student temp;

	while(scanf("%d",&n) != EOF)
	{
		//接收数据
		for(i = 0; i < n; i++)
		{
			scanf("%d%d",&students[i].number,&students[i].score);
		}

		//冒泡排序
		for(i = 0; i < n - 1; i ++)
		{
			for(j = 0; j < n - i - 1; j ++)
			{
				if(students[j].score > students[j + 1].score)
				{
					temp = students[j];
					students[j] = students[j + 1];
					students[j + 1] = temp;
				}else if(students[j].score == students[j + 1].score)
				{
					if(students[j].number > students[j + 1].number)
					{
						temp = students[j];
						students[j] = students[j + 1];
						students[j + 1] = temp;
					}
				}
			}
		}

		//输出排序结果
		for(i = 0; i < n; i ++)
		{
			printf("%d %d\n",students[i].number,students[i].score);
		}
	}
	
	return 0;
}
/**************************************************************
	Problem: 2212
	User: admin
	Language: C++
	Result: Accepted
	Time:10 ms
	Memory:1144 kb
****************************************************************/