In poker, each player holds 5 playing cards. At the end of the final round every player reveals their cards, and the player with the most valuable hand wins. Your task is to read the poker hand of each player, rank the hands by their relative worth, and print them from most to least valuable.
Poker is played with a deck of 52 cards divided evenly into 4 suits: hearts (♥), spades (♠), diamonds (♦), and clubs (♣). Each suit has 13 cards, and each card has a rank that determines its worth. From highest to lowest these ranks are: ace (high), king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, 2, ace (low). Although each suit has only one ace and it usually ranks as the highest card, in some situations the ace is treated as the lowest card. The suit itself does not affect a card's worth; it is only used to decide whether a hand is a flush or a straight flush (see below).
Every poker hand falls into exactly one of nine categories based on the combination of cards it contains. A higher category always beats a lower category, regardless of the individual card ranks. When two hands share the same category, the individual card ranks break the tie, and each category has its own tie-breaking rule. The order of the cards within a hand does not affect its category. The categories are listed below from most to least valuable.
The first line contains a single integer N (1 ≤ N ≤ 100), the number of data sets. Each data set begins with a line containing an integer M (1 ≤ M ≤ 100), the number of poker hands in the data set. The next M lines each describe one hand: five cards separated by spaces, where each card is a two-character string.
A, K, Q, J for ace, king, queen, and jack; 0 (the digit zero) for a 10; and 2 through 9 for the matching numeric rank.H, S, D, C for hearts, spades, diamonds, and clubs.Within a single hand the same card (same rank and suit) never appears more than once.
For each data set, first print the heading Data Set #k, where k is 1 for the first data set, 2 for the second, and so on. After the heading, print the hands in that data set in order from most to least valuable, one per line. The cards within each hand must be printed in the same order in which they were read. No two hands in a data set have the same worth, so the sorted order is always unique.