n=int(input()) arr=list(input().split()) arr=sorted(arr,key=lambda x:x[1]) arr=sorted(arr,key=lambda x:x[0]) for i in range(n): print(*arr[i])