Class Time

Sort the student names by last name, breaking ties by first name, and print them in that order.

Easy3SortingInterviewNo attempts yetTime limit2sMemory limit256 MB

Problem

It is the first day of class. Tom is teaching the class, and before anything else he takes attendance to see who showed up.

Tom calls the students in alphabetical order by last name. When two or more students share a last name, he calls those students in alphabetical order by first name.

Given the roster, print the order in which Tom calls the students.

Input

The first line contains an integer nn, the number of students in Tom's class. (1n1001 \le n \le 100)

Each of the next nn lines contains the name of one student: the first name, a single space, then the last name. Both the first name and the last name start with an uppercase letter (A to Z) followed by one or more lowercase letters (a to z). Neither the first name nor the last name is longer than 10 letters.

No two students have exactly the same first name and last name, but students may share a first name, or share a last name.

Output

Print nn lines with the student names in the order Tom calls them. Write each line in the same format as the input: the first name, a single space, then the last name.