The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:

The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.

If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).

For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew.
The first line contains an integer *n*, which is the number of people in the crew (1 ≤ *n* ≤ 100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain.
none
6
Jack captain
Alice woman
Charlie man
Teddy rat
Bob child
Julia woman
Teddy
Alice
Bob
Julia
Charlie
Jack
1
A captain
A
1
Abcdefjhij captain
Abcdefjhij
5
A captain
B man
D woman
C child
E rat
E
D
C
B
A
10
Cap captain
D child
C woman
A woman
E child
Man man
B child
F woman
Rat rat
Ratt rat
Rat
Ratt
D
C
A
E
B
F
Man
Cap
5
Joyxnkypf captain
Dxssgr woman
Keojmnpd rat
Gdv man
Hnw man
Keojmnpd
Dxssgr
Gdv
Hnw
Joyxnkypf
11
Jue rat
Wyglbyphk rat
Gjlgu child
Gi man
Attx rat
Theorpkgx man
Ym rat
X child
B captain
Enualf rat
Kktsgyuyv woman
Jue
Wyglbyphk
Attx
Ym
Enualf
Gjlgu
X
Kktsgyuyv
Gi
Theorpkgx
B
22
Wswwcvvm woman
Btmfats rat
I rat
Ocmtsnwx man
Urcqv rat
Yghnogt woman
Wtyfc man
Wqle child
Ujfrelpu rat
Dstixj man
Ahksnio woman
Khkvaap woman
Sjppvwm rat
Egdmsv rat
Dank rat
Nquicjnw rat
Lh captain
Tdyaqaqln rat
Qtj rat
Tfgwijvq rat
Nbiso child
Nqthvbf woman
Btmfats
I
Urcqv
Ujfrelpu
Sjppvwm
Egdmsv
Dank
Nquicjnw
Tdyaqaqln
Qtj
Tfgwijvq
Wswwcvvm
Yghnogt
Wqle
Ahksnio
Khkvaap
Nbiso
Nqthvbf
Ocmtsnwx
Wtyfc
Dstixj
Lh
36
Kqxmtwmsf child
Ize woman
Dlpr child
K woman
F captain
Rjwfeuhba rat
Bbv rat
S rat
Mnmg woman
Smzyx woman
Sr man
Qmhroracn rat
Soqpuqock rat
Pibdq man
Ilrkrptx rat
Zaecfyqka man
Mmersfs child
Vvvocqi man
Hjeqxvq rat
Mpmb woman
Wmgu woman
Cerelmhoxi child
A man
Dylv man
Xrdgmmtcpq woman
Xj woman
Ceh child
Ofccguo man
Nevr man
Aknkwdkq child
Bmo man
Lqo woman
Vej child
T child
Rlijc man
Nsdtpdg woman
Rjwfeuhba
Bbv
S
Qmhroracn
Soqpuqock
Ilrkrptx
Hjeqxvq
Kqxmtwmsf
Ize
Dlpr
K
Mnmg
Smzyx
Mmersfs
Mpmb
Wmgu
Cerelmhoxi
Xrdgmmtcpq
Xj
Ceh
Aknkwdkq
Lqo
Vej
T
Nsdtpdg
Sr
Pibdq
Zaecfyqka
Vvvocqi
A
Dylv
Ofccguo
Nevr
Bmo
Rlijc
F
2
A captain
B man
B
A
2
B woman
A captain
B
A
2
X child
Y captain
X
Y
2
X captain
Y rat
Y
X
6
Abdelrhman captain
Alice woman
Charlie man
Teddy rat
Bob child
Julia woman
Teddy
Alice
Bob
Julia
Charlie
Abdelrhman
4
Aratos captain
Mind child
Aman woman
Carrot man
Mind
Aman
Carrot
Aratos
n = int(input())
member = {'rat':[],'k':[],'man':[],'captain':[]}
for i in range(n):
    name,clas = input().split()
    if clas=='woman' or clas=='child':
        clas = 'k'
    member[clas].append(name)
for i in member:
    for j in member[i]:
        print(j)