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

typedef struct Grade
{
    int Order;
    int Point;
}Grade;

int cmp(const void *a,const void *b)
{
    if(((Grade*)a)->Point==((Grade*)b)->Point)
        return ((Grade*)a)->Order>((Grade*)b)->Order;
    return ((Grade*)a)->Point>((Grade*)b)->Point;
}

int main()
{
    int Num;
    scanf("%d",&Num);
    Grade G[Num];
    for(int i=0;i<Num;i++)
    {
        scanf("%d%d",&G[i].Order,&G[i].Point);
    }
    //以上将所有数据录入
    
    qsort(G,Num,sizeof(Grade),cmp);
    
    for(int i=0;i<Num;i++)
        printf("%d %d\n",G[i].Order,G[i].Point);
    return 0;
}