n = int(input()) hon = [input.split() for i in range(n)] hon.sort(key=lambda x:(x[0],x[1])) for h in hon: print(h)