Mentors and Mentees
InterviewTime limit2sMemory limit256 MB
Sort mentor-mentee pairs by mentor in dictionary order, and break ties by mentee in reverse dictionary order.
Problem
Seoul Cyber University runs a mentoring program. In this program, one mentor (a senior student) passes on know-how and information about college life to several mentees (junior students).
Professor Noh runs deep learning servers at the Big Data AI Center and has been busy for a while. One day he received a request to attend a mentoring meeting. While preparing, he found a notebook listing mentor-mentee pairs. The notebook was not organized, so it was hard to analyze. He asked Tturu, a graduate student interning at the center, to sort the list.
Tturu, however, was short on sleep from writing a paper and had no time to write such a program. So he handed the list to you. Given the list, sort it in dictionary order by mentor. Pairs with the same mentor should be sorted by mentee in reverse dictionary order.
Input
The first line contains the number of mentor-mentee pairs . ()
From the second line onward, the next lines each contain the mentor's name and the mentee's name, separated by a single space. Names consist only of lowercase letters and are no longer than 20 characters. A can be the mentor of B while B is also the mentor of A. A mentor and mentee can be the same person. No mentor-mentee pair is given more than once.
Output
Print lines with the sorted mentor-mentee pairs in the same format as the input.