Problem 1

2012 ACU Programming Contest Series

Problem 1: Poker

The Accelerated Card Union (ACU) prides itself on quick and accurate decisions about winning hands in ACU Poker. To insure both quick and correct evaluations, ACU's dealers are always practicing poker.

Poker is played with a regular deck of 52 cards including one of each of four suits (in order: s, h, d, and c) and thirteen ranks (in order: A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2). Each 5-card hand can be described by the following ordered list; better hands are listed first.

  1. a Royal Flush: A, K, Q, J, and T all of the same suit
  2. a Staight Flush: a hand that is both a Straight and a Flush
  3. Four of a Kind: four cards of the same rank
  4. a Full House: Three of a Kind and a Pair of different ranks
  5. a Flush: five cards of the same suit
  6. a Straight: five cards of consecutive rank, an A can be high (above king) or low (below 2)
  7. Three of a Kind: three cards of the same rank
  8. Two Pair: two Pairs of different ranks
  9. a Pair: two cards of the same rank
  10. a High Card: none of the above

Ties are broken by considering the highest card (rank, then suit) from amoung the cards described in the definitions above. In a Full House, consider the Three of a Kind before considering the Pair. In a Straight in which A is played low, consider A less than 2.

Write a program to compare two poker hands and determine the winning hand.

Input

The first line of input consists of a single integer on a line by itself specifying the number of data sets to consider.

The input for each data set is on a single line consisting of ten pairs of letters separated by a single space. Each pair consists of the rank and suit of a card, respectively. The first five cards make up Abe's hand; the last five make up Bob's hand.

    

Output

Each data set should produce one line of output indicating the name of the winner and the value of his poker hand as shown below.

Sample input:
3
Ks As Js Ts Qs 2s 3h 4c 5d 2d
2s 3d 4s 3s 4h Td 9d 8d Kd 4c
3c 4c 5c 7c 6c 3s 7s 6s 5s 4s 
     Sample output:

Abe wins with a Royal Flush
Bob wins with a High Card
Bob wins with a Straight Flush