n=int(input()) li=[] for i in range(n): age,name=map(str,input().split()) age=int(age) li.append([age,name]) li.sort(key=lambda li:li[0]) for j in li: print(j[0],j[1])