Poker is played with a standard 52-card deck (no jokers). Every card has a rank and a suit.
The card ranks, in ascending order, are: A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A (note that A can be either high or low). The card suits, in ascending order, are: Clubs (c), Diamonds (d), Hearts (h), Spades (s). The suit order is used only for display and never affects the value of a hand or a card. This gives 13 x 4 = 52 cards in a deck.
A poker hand consists of five cards. The possible hands are listed below from best to worst, with an example in bold for each.
Hold 'em is a variation of poker. Each player receives two cards face down, called hole cards. Five more cards, called the board, are placed face up in the middle of the table. A player's hand is the best five-card poker hand that can be formed from any combination of their two hole cards and the five board cards.
You know the five board cards and your own two hole cards (seven cards in total). An opponent's two hole cards are two cards you cannot see, chosen from the remaining cards in the deck. Determine the best possible five-card hand an opponent could make. (Given any seven cards you can see, an opponent can always make at least a three of a kind, so no weaker hand ever needs to be reported.)
The first line contains a single integer n, the number of data sets.
Each data set is a single line of seven two-character strings separated by single spaces. Each string is a card: the first character is the rank and the second is the suit. The first five cards are the board and the last two are your own hole cards. The cards are given in no particular order.
For each data set, output on its own line the best five-card hand an opponent might make, followed by the name of that hand.
List the five cards in descending order: by rank first (an Ace is always treated as high for display), then by suit. If a card in the best hand could be of two or more different suits (that is, the suit is tied), print its suit as *; when ordering by suit, * is treated as the lowest suit.
After the five cards, print the name of the hand. The possible names are: ROYAL FLUSH, STRAIGHT FLUSH, FOUR OF A KIND, FULL HOUSE, FLUSH, STRAIGHT, THREE OF A KIND.