9440 - Stable Sort   

Description

Given the grades of N people. Please output the sorted result. (Increasing order)

Input

The input includes multiple test cases.
In each test case, the first line contains one integer N. The following N lines specify the name Si and the grade Gi.

The input is terminated by EOF.

For all the cases,
1 <= |Si| <= 10
0 <= Gi <= 100 (Gi is an integer.)

Range of N is different for each case.
Case 1: 1 <= N <= 103
Case 2: 1 <= N <= 104
Case 3: 1 <= N <= 105
Case 4: 1 <= N <= 106

Output

For every test case, output the result in N lines. Every line contains the name and the grade. If more people’s grades are same, output by input order. (That means it uses stable sort.)

Sample Input  Download

Sample Output  Download

Tags




Discuss