Dossiers
The following information about all pupils of a school is available: surname, first name, class, date of birth. Depending on situation, Director may need to sort it in different modes. Full list of standard sort modes is:
surname - by surname, ignoring first name;
fullname - first by surname, then by first name for equal surnames;
birthyear - by year of birth, ignoring date inside year, from earlier years (elder pupils) to later years (younger pupils);
birthdate - by date of birth, i. e. first by year, then by month, then by day, from earlier dates (elder pupils) to later dates (younger pupils);
birthday - by birthdays, from 01.01 to 31.12 (in DD.MM format), considering the same dates of different years equal;
grade - by class (1 – 11) as year of study, ignoring letter;
class - first by grade (year of study), then by class letter (A – Z) for equal grades.
Sometimes Director needs to use first one of the modes, then another (for pupils equal by first mode), etc. For фexample, “birthyear grade surname” means to place firstly all pupils who were born in 1998, then all who were born in 1999, etc; pupils, who were born in the same year, should be sorted by grade (class ignoring letter); finally, pupils who were born in the same year and are studying in the same grade should be sorted by surnames.
Input
The first line contains required sort mode, as one or some of words surname, fullname, birthyear, birthdate, birthday, grade, class. At least one word will appear; no word can appear more than once. If there are several words, they are separated by single spaces.
The second line contains the quantity of pupils n (2 ≤ n ≤ 12345).
The following text contains n four-line groups, describing a pupil. First line of each group contains surname. Surname must begin with capital Latin letter, which can be followed by sequence of Latin letters, hyphens (-) and apostrophes (’). Second line of each group contains first name. First name must begin with capital Latin letter, which can be followed by sequence of Latin letters, hyphens (-), apostrophes (’) and spaces ( ). Third line of each group contains date of birth, given in format DD.MM.YY, i. e. exactly two digits for dayof-month, point, exactly two digits for month, point, exactly two digits for year. Fourth line of each group contains class - integer number from 1 to 11 and exactly one capital Latin letter, without space between.
All dates of birth are correct (for example, it cannot be 30.02) and are in range from 1990 to 2030. It means that, for example, 97 < 02, because 97 means 1997 and 02 means 2002. Typically, pupils of higher classes have earlier dates of birth, but this rule can have exceptions.
Major (at least 99.9%) of surnames and first names are not longer than 20 characters, but all we know about the rest 0.1% is that their total length is not greater then one million characters. Surnames and first names may end with Latin letter or apostrophe, and cannot end with hyphen or with space. You should compare surnames with surnames and first names with first names, using standard case-sensitive string comparing, implemented in programming language (even if names contain apostrophes or other non-letter symbols).
Output
Program should print exactly n lines. Each line should contain information about one pupil, in format: class, comma, surname, comma, first name, comma, date of birth. Each of class, surname, first name and date of birth should be byte-in-byte the same, as in input data. Lines should be sorted according to the specified sort modes.
In all cases, when applying of the specified sorting modes to the specified input data leaves the possibility of different correct answers, program should output any one of them. For example, for specified sort modes “birthyear grade surname”, if there are pupils of the same year of birth, studying in the same grade and having the same surname - they can be written in any order, each exactly once.
Sample Input Sample Output
birthyear grade surname 11A, Ivanov, Kirill, 12.01.97 8 11B, Ivanov, Andrey, 23.12.97 Gonsales 11B, Petrova, Natalia, 23.08.97 Anna Maria 9A, Smirnov-Kovalenko, Egor, 13.11.98 5A 10A, Shevchenko, Denis, 07.05.98 01.05.03 11B, Andreeva, Ekaterina, 07.02.98 Ivanov 5A, Gonsales, Anna Maria, 01.05.03 Kirill 3D, Ivanov, Ivan, 20.01.05 11A 12.01.97 Ivanov Ivan 3D 20.01.05 Ivanov Andrey 11B 23.12.97 Petrova Natalia 11B 23.08.97 Andreeva Ekaterina 11B 07.02.98 Shevchenko Denis 10A 07.05.98 Smirnov-Kovalenko Egor 9A 13.11.986