Under construction

Still being built. Things may change

Olympiad Registration

Interview

Time limit2sMemory limit512 MB

Summary
Each row was written in one of two field orders; use the guarantee that every first name appears at least twice to recover each participant's surname, given name, and patronymic, then sort by surname.
Level

Medium5 of 10

Topics
Hash map, String, Sorting, Implementation
Solved
No attempts yet

Problem

Petya and Vasya are running a programming olympiad. So many participants showed up that Petya and Vasya had to work together to register all of them.

To register, each participant states their first name, last name, and patronymic, and Petya and Vasya enter this information into a shared spreadsheet. Because there are many participants and so little time to organize, Petya and Vasya did not agree on a format for writing a participant's data into the table and had to improvise. Petya decided to write each participant's last name first, then first name, then patronymic, while Vasya wrote first name first, then patronymic, then last name.

After registration ended, it became clear that this table could not be used to summarize the olympiad results: it would be inconvenient for a participant to find themselves. They decided to bring the table to the following form:

  • for every participant, the last name is written first, then the first name, then the patronymic;
  • the participants in the table are ordered lexicographically by last name.

Lexicographic order matches the order in dictionaries: words are compared by the first letter, then by the second, and so on. If the current letter in one word is smaller, that word is lexicographically smaller than the other. If no difference is found, that is, one of the words is a prefix of the other, then it is considered smaller.

Petya and Vasya noticed that all participants have distinct last names, while every first name occurs at least twice. No first name is a last name or patronymic of any participant, and likewise no last name and patronymic coincide.

Using this information, help them bring the table to the desired form.

Input

The first line contains the number nn (2≤n≤10002 \le n \le 1000), the total number of records in the spreadsheet. Then nn lines each contain three words s1,is_{1,i}, s2,is_{2,i}, s3,is_{3,i}. Each word contains from 1 to 20 Latin letters, the first letter is uppercase and all the rest are lowercase. Each line corresponds to one of the records made by Petya or Vasya. The words are separated by a single space.

Output

Output nn lines: the spreadsheet in which each participant has the last name first, then the first name, then the patronymic, with all records sorted lexicographically.

Examples1

  1. Example 1

    Input
    4
    Ivanov Ivan Ivanovich
    Ivan Borisovich Petrov
    Sergey Ivanovich Sidorov
    Pavlov Sergey Borisovich
    
    Expected output
    Ivanov Ivan Ivanovich
    Pavlov Sergey Borisovich
    Petrov Ivan Borisovich
    Sidorov Sergey Ivanovich