I=["iti","ni","san","yon"] N=int(input()) S=[input().split() for i in range(N)] for i in range(N):S[i][1] = I.index(S[i][1]) S.sort() for a, b in S:print(a, I[b])