n=int(input()) for x in sorted([input().split()for _ in range(n)],key=lambda x:(x[0],'insy'.find(x[1][0])+1)):print(*x)