By Neilor Tonin, URI Brasil
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.
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.
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|
branco P Cezar Torres Mo