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.
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 (2 \leqslant N \leqslant 12345).
The following text contains four-line groups, describing a pupil: (1) surname — begins with capital Latin letter, followed by sequence of Latin letters, hyphens (-) and apostrophes ('); (2) first name — begins with capital Latin letter, followed by sequence of Latin letters, hyphens (-), apostrophes (') and spaces; (3) class — integer number from 1 to 11 and exactly one capital Latin letter, without space between; (4) date of birth (DD.MM.YY, i.e. day, month, and year are always given as exactly two digits each).
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 than 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).
Program should print exactly lines. Each line should contain information about one pupil, in format: class, comma, space, surname, comma, space, first name, comma, space, 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.
Example
birthyear grade surname
8
Gonsales
Anna Maria
5A
01.05.03
Ivanov
Kyrylo
11A
12.01.97
Ivanov
Ivan
3D
20.01.05
Ivanov
Andrii
11B
23.12.97
Petrenko
Nataliia
11B
23.08.97
Andrijchenko
Kateryna
11B
07.02.98
Shevchenko
Denys
10A
07.05.98
Smirnov-Kovalenko
Yehor
9A
13.11.9811A, Ivanov, Kyrylo, 12.01.97
11B, Ivanov, Andrii, 23.12.97
11B, Petrenko, Nataliia, 23.08.97
9A, Smirnov-Kovalenko, Yehor, 13.11.98
10A, Shevchenko, Denys, 07.05.98
11B, Andrijchenko, Kateryna, 07.02.98
5A, Gonsales, Anna Maria, 01.05.03
3D, Ivanov, Ivan, 20.01.05The answer in which Ivanov Andrii and Ivanov Kyrylo are swapped is also correct. There are no other correct answers for this input data besides these two.
C# language, unlike most programming languages, has a slightly different understanding of standard case-sensitive lexicographic string comparison, so instead of the obvious fragment p1.surName.CompareTo(p2.surName) you should write String.Compare(p1.surName, p2.surName, StringComparison.Ordinal), and similarly in other cases where this matters.