시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 256 MB 16 12 12 75.000%

문제

It’s the first day of class! Tom is teaching class and first has to take attendance to see who is in class. He needs to call the students’ names in alphabetical order by last name. If two students have the same last name, then he calls the students with that same last name in alphabetical order by first name. Help him!

입력

The first line of input contains an integer n (1 ≤ n ≤ 100), the number of students in Tom’s class. Each of the following n lines contains the name of a single student: first name, followed by a single space, then last name. The first and last name both start with an uppercase letter (‘A’–‘Z’) and then be followed by one or more lowercase letters (‘a’–‘z’). The first and last name of each student is no more than 10 letters long each.

It is guaranteed that no two students have exactly the same name, though students may share the same first name, or the same last name.

출력

Output n lines, the names of the students as Tom calls them in the desired order.

예제 입력

3
John Adams
Bob Adam
Bob Adams

예제 출력

Bob Adam
Bob Adams
John Adams

예제 입력 2

1
Coursera Educators

예제 출력 2

Coursera Educators

힌트