n = int(input()) nam = [] for i in range(n): s,j = map(str,input().split()) nam.append([s,j]) nam.sort(key=lambda x:(x[0],x[1])) for i in nam: print(*i)