#include <iostream> #include<algorithm> typedef struct student{ int snum; int score; }; using namespace std; bool Compare(student a,student b){ if(a.score==b.score){ return a.snum<b.snum; }else { return a.score<b.score; } } int main() { int n; while(scanf("%d",&n)!=EOF){ student stu[n]; for(int i=0;i<n;i++){ scanf("%d %d",&stu[i].snum,&stu[i].score); } sort(stu,stu+n,Compare); for(int j=0;j<n;j++){ printf("%d %d\n",stu[j].snum,stu[j].score); } } }