Problem G: SpaceRecon Tournament

SpaceRecon, the hottest game of 2011, is a real-time strategy thriller where players control your armies to destroy their opponent. Players may choose from one of the three available races -- Xurks (biological), Protoast (technological), and Earthians (humanoids) -- to build their respective armies by collecting resources from the land and spending them on army units, upgrades, and infrastructure. The player who destroys or outlasts their opponent is victorious.

The game has an intricate single-player story mode where players recreate scenes of the survival of Earthian Commander John Rainard's travels through the Xurkling planet, and also the charades of once-Earthian-now-Xurkling Queen Stephanie Karpenter. After completing the 15 hours of single player gameplay, most users try their hand at multiplayer head-to-head battles online using Actionweb, the number one SpaceRecon game matching hub.

Actionweb hosts tournaments of 2^M players and publishes the results of each tournament by listing each player handle and the number of match victories in the tournament. Tournaments are series of head-to-head matches between two players, the winner of the round advancing to the next round. The first R rounds are best of three (i.e., win two matches to win the round, any unnecessary games are not played), the remaining rounds are best of five (i.e., win three matches to win the round, any unnecessary games are not played). Each tournament has a different value of R, but is not published.

Input Format

The first line is an integer N (1 <= N <= 100), the number of test cases, which follow. Each test case begins with a line containing an integer M (1 <= M <= 10). The following 2^M lines are of format "player_handle number_of_match_victories". Player handles are alphanumeric and between 1 and 16 characters long.

You may assume that the data provided describes a valid tournament.

Output Format

Print the player handles sorted in descending order of which round they survived to. For players who survived the same number of rounds, sort them lexicographically by player handle.

Sample Input

1
2
John 1
Jake 5
Joe 4
Jane 0

Sample Output

Jake
Joe
Jane
John

Sean McIntyre
ACPC 2011