URI Online Judge | 1258

T-Shirts

By Neilor Tonin, URI  Brasil

Timelimit: 1

Professor Rolien and their Computer Science students are making a polo shirt that need to be both beautiful and inexpensive. After some meetings, it was agreed with the students that would be made ​​only black shirts but the students could choose between the color details (white or red). Therefore, Rolien needs your help to arrange the lists for all classes for those that want to by the shirt, relating these shirts by color details, size (P: small), M or (G:large) and lastly by name.

Input

The input contains several test cases. Each test case begins with a integer and positive N (1 ≤ N ≤ 60), that indicates the amount of shirts that will be made for that class. The next N*2 lines contains information of each shirt (will be two lines of information for each shirt). The first line will contain the student's name and the second line will contain the color of the shirt details ("branco" -white or "vermelho" -red) followed by a space and the size of the shirt "P" "M" or "G". The input ends when the value of N equals zero (0) and this number should not be processed.

Output

For each test case print the information sorted by color details in ascending order, followed by size in descending order and at last, by name in ascending order, as shown below.

Note: should be printed a blank line between two test cases.

Sample Input Sample Output

9
Maria Jose
branco P
Mangojata Mancuda
vermelho P
Cezar Torres Mo
branco P
Baka Lhau
vermelho P
JuJu Mentina
branco M
Amaro Dinha
vermelho P
Adabi Finho
branco G
Severina Rigudinha
branco G
Carlos Chade Losna
vermelho P
3
Maria Joao
branco P
Marcio Guess
vermelho P
Maria Jose
branco P
0

branco P Cezar Torres Mo
branco P Maria Jose
branco M JuJu Mentina
branco G Adabi Finho
branco G Severina Rigudinha
vermelho P Amaro Dinha
vermelho P Baka Lhau
vermelho P Carlos Chade Losna
vermelho P Mangojata Mancuda

branco P Maria Joao
branco P Maria Jose
vermelho P Marcio Guess