9152 - Stable Sort   

Description

Given the grades of N people.
Output the sorted result in ascending order.


Hint: Ascending order is an order of sorting that starts with the lowest value and proceeds to the highest value

Input

The first line of input contains a positive integer t , which indicates the number of 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.

t <= 60
1 <= |Si| <= 7
0 <= Gi <= 100 (Gi is an integer.)
test case 1: 1 <= N <= 103
test case 2: 1 <= N <= 104
test case 3: 1 <= N <= 105
test case 4: 1 <= N <= 5*106

Output

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