for h in sorted([input().split() for i in range(int(input()))], key=lambda x:(x[0],x[1])): print(" ".join(h))