This page is still under construction.

Parts of this page are still being built. What you see may change.

Mentors and Mentees

Interview

Time limit2sMemory limit256 MB

Summary
Sort mentor-mentee pairs by mentor in dictionary order, and break ties by mentee in reverse dictionary order.
Level

Easy2 of 10

Topics
Sorting, String
Solved
No attempts yet

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 NN. (1≤N≤100 0001 \le N \le 100\,000)

From the second line onward, the next NN 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 NN lines with the sorted mentor-mentee pairs in the same format as the input.

Examples2

  1. Example 1

    Input
    5
    alice bob
    alice dave
    eve mallory
    peggy victor
    alice carol
    
    Expected output
    alice dave
    alice carol
    alice bob
    eve mallory
    peggy victor
    
  2. Example 2

    Input
    8
    cgiosy jhnah
    son kim
    son lee
    cgiosy leejseo
    cgiosy junseo
    son hwang
    cgiosy sean
    cgiosy cologne
    
    Expected output
    cgiosy sean
    cgiosy leejseo
    cgiosy junseo
    cgiosy jhnah
    cgiosy cologne
    son lee
    son kim
    son hwang