n = int(input()) d = {x: i for i, x in enumerate(["iti", "ni", "san", "yon"])} A = [input().split() for i in range(n)] A.sort(key=lambda x: (x[0], d[x[1]])) for a in A: print(*a)