10746 - 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.

1 <= |Si| <= 10
0 <= Gi <= 100 (Gi is an integer.)

Test Case 1 : 1 <= N <= 102
Test Case 2 : 1 <= N <= 104
Test Case 3 : 1 <= N <= 105
Test 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