from collections import *

inf = open('names.in')
out = open('names.out', 'w')

n = int(inf.readline())
a = [inf.readline().split() for i in range(n)]

d = Counter(x for xx in a for x in xx)

for i in sorted((x, y, z) if d[x] == 1 else (z, x, y) for x, y, z in a):
    print(*i, file=out)
