s=["iti","ni","san","yon"] n=int(input()) a=[] for _ in range(n): t,u=input().split() a.append([t,s.index(u)]) a.sort() for b,c in a:print(b,s[c])