시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB23518116277.885%

문제

Jane has many friends, but she likes some less than others. She has a number associated with each friend which represents how much she likes each friend. The higher the number, the more she likes that friend. Given her list of friends, sort them so that the best friends are at the top and the least best friends are at the bottom.

입력

The first line of input will contain a single integer n that indicates the number datasets to follow. Each dataset will consist an integer m, (0 < m < 500), which is the number of friends that will be in the dataset. The next m lines will have the format “name num”, where name is the name of the friend and num (0 < num < 500) is the number that represents how much she likes her friend. The name will only be one word. No two friends will not have the same num value.

출력

Output a list of names, separated by a comma and one space, of the friends in order of how much Jane likes them.

예제 입력 1

2
2
bill 2
greg 5
4
jim 5
phil 8
paul 7
rob 2

예제 출력 1

greg, bill
phil, paul, jim, rob