Poker Game: Construction

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Alice and Bob invent a new game based on Texas hold'em. Please read the following rules carefully as they are different from the usual rules. The background of this problem is exactly the same as problem D.

There are 1313 ranks, which are A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, and 2 from high to low. There are 44 suits, which are S, H, C, and D. Every combination of a rank and a suit occurs exactly once, so there are 5252(=13×4=13\times 4) cards.

A hand is a set of five cards. Each hand has a rank. There are 1010 types of hands. Each type also has a rank. If two hands are of different types, the hand of the type with a higher rank always ranks higher. A hand can be represented as a sequence (r_1,r_2,r_3,r_4,r_5)(r\_1,r\_2,r\_3,r\_4,r\_5), where r_ir\_i is the rank of the ii-th card and the order of the five cards depends on the type of the hand. If two hands are of the same type, the hand represented as the lexicographically larger sequence ranks higher: formally, if we find the smallest index ii such that r_ir\_i of two hands are different, the hand with higher r_ir\_i ranks higher. If the types and the sequences rr of two hands are equal, two hands have the same rank.

The 1010 types are given below, from lowest to highest rank. If a hand matches the patterns of multiple types, it belongs to the one with the highest rank.

  • Highcard: Any five cards. The sequence rr satisfies r_1>r_2>r_3>r_4>r_5r\_1>r\_2>r\_3>r\_4>r\_5.
  • Pair: Two cards with the same rank. The sequence rr satisfies r_1=r_2r\_1=r\_2, r_3>r_4>r_5r\_3>r\_4>r\_5.
  • Two pairs: Two cards with the same rank and another two cards with the same rank. The sequence rr satisfies r_1=r_2>r_3=r_4r\_1=r\_2>r\_3=r\_4.
  • Three of a kind: Three cards with the same rank. The sequence rr satisfies r_1=r_2=r_3r\_1=r\_2=r\_3, r_4>r_5r\_4>r\_5.
  • Straight: Five cards with five consecutive ranks. The sequence rr satisfies r_1>r_2>r_3>r_4>r_5r\_1>r\_2>r\_3>r\_4>r\_5. Additionally, A 2 3 4 5 is a straight, and A is regarded as a rank lower than 2 in this case. Hence A 2 3 4 5 is the straight with the lowest ranks.
  • Flush: Five cards with the same suit. The sequence rr satisfies r_1>r_2>r_3>r_4>r_5r\_1>r\_2>r\_3>r\_4>r\_5.
  • Full house: Three cards with the same rank and another two cards with the same rank. The sequence rr satisfies r_1=r_2=r_3r\_1=r\_2=r\_3, r_4=r_5r\_4=r\_5.
  • Four of a kind: Four cards with the same rank. The sequence rr satisfies r_1=r_2=r_3=r_4r\_1=r\_2=r\_3=r\_4.
  • Straight flush: A straight with the same suit. The sequence rr satisfies r_1>r_2>r_3>r_4>r_5r\_1>r\_2>r\_3>r\_4>r\_5. Additionally, A 2 3 4 5 with the same suit is a straight flush, and A is regarded as a rank lower than 2 in this case. Hence A 2 3 4 5 with the same suit is the straight flush with the lowest ranks.
  • Royal flush: Straight flush with the ranks T, J, Q, K, and A. Four different royal flushes are of the same rank.

Two cards are dealt to each of Alice and Bob. Instead of the regular rules, 66 community cards are dealt. Two players take community cards one by one, in turn, until each player has five cards, completing a hand. Alice takes first. The player who has a hand with higher rank wins. If two hands have same rank, there is a draw. Note that all ten cards are shown to both, and they always choose the optimal strategy.

The above are the same in problem D. The task is the following.

Given the cards of Alice and the cards of Bob, find possible 66 community cards such that Alice wins, that Bob wins, and that there is a draw.

입력

There are multiple test cases. The first line of input contains an integer TT (1T1051\le T\le 10^5), the number of test cases. For each test case:

The first line contains two strings a_1a\_1 and a_2a\_2: Alice's initial cards.

The second line contains two strings b_1b\_1 and b_2b\_2: Bob's initial cards.

The third line contains six strings c_1c\_1, c_2c\_2, c_3c\_3, c_4c\_4, c_5c\_5, and c_6c\_6: the community cards.

Each string is of length two. The first character is one of "A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2", which represents the rank of a card. The second character is one of "S", "H", "C", "D", which represents the suit of a card.

It is guaranteed that all 44 given cards are pairwise distinct.

출력

For each test case:

Print a single line for each of the three questions: how to make Alice win, how to make Bob win, and how to make the game end in a draw. For each question, if it is possible, output "YES" and 66 strings representing the 66 cards; otherwise, output "NO".

The format of the cards in the output should be the same as the format in the input.

All 1010 cards in input and output must be pairwise distinct.