for i in sorted(dict(j.split() for j in open(0).readlines()[1:]).items()): print(*i)