Poker Game: Construction
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

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 13 ranks, which are A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, and 2 from high to low. There are 4 suits, which are S, H, C, and D. Every combination of a rank and a suit occurs exactly once, so there are 52() cards.

A hand is a set of five cards. Each hand has a rank. There are 10 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), where r_i is the rank of the i-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, i.e., find the smallest index i such that r_i of two hands are different, the hand with higher r_i ranks higher. If the types and the sequences r of two hands are equal, two hands have the same rank.

The 10 types are given in the following from low rank to high rank. If a hand matches the patterns of multiple types, it belongs to the one with the highest rank of them.
  • Highcard: Any five cards. The sequence r satisfies that .
  • Pair: Two cards with the same rank. The sequence r satisfies that , .
  • Two pairs: Two cards with the same rank and another two cards with the same rank. The sequence r satisfies that .
  • Three of a kind: Three cards with the same rank. The sequence r satisfies that , .
  • Straight: Five cards with five consecutive ranks. The sequence r satisfies that . Especially, A 2 3 4 5 is a straight, and A is regarded as a rank lower than 2 in the situation. Hence A 2 3 4 5 is the straight with the lowest ranks.
  • Flush: Five cards with the same suit. The sequence r satisfies that .
  • Full house: Three cards with the same rank and another two cards with the same rank. The sequence r satisfies that , .
  • Four of a kind: Four cards with the same rank. The sequence r satisfies that .
  • Straight flush: A straight with the same suit. The sequence r satisfies that . Especially, A 2 3 4 5 with the same suit is a straight flush, and A is regarded as a rank lower than 2 in the situation. 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 rule, 6 community cards are dealt. Two players take one card from the community cards in turn until each player has five cards, also a hand. Alice takes first. The player who has a hand with higher ranks wins. If two hands are with the 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 as problem D. The task is the following.

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

输入描述:

There are multiple test cases. The first line of input contains an integer T(), the number of test cases. For each test case:

The first line contains two strings a_1, a_2 -- Alice's hole cards.

The second line contains two strings b_1, b_2 -- Bob's hole 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 any two of the four cards are different.

输出描述:

For each test case:

For each of that Alice wins, that Bob wins and that there is a draw, if it is possible, output ”YES” and 6 strings representing the 6 cards; otherwise, output ”NO”.

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

Any two of the ten cards in input and output must be different.
示例1

输入

复制
3
JC 4H
TS 5D
7C 3C
7H TH
2D KH
4D JC

输出

复制
YES JS JH JD 4S 4C 4D
YES TH TC TD 5S 5H 5C
YES 4S JS 5S TH TC TD
YES 3S 3H 3D 2C 4H 5S
YES 2H 4H 5H 6H 8H 9H
YES TS 3S 2S 2H 4C 4D
YES 2S 2H 2C KS KC KD
YES 4S 4H 4C JS JH JD
YES 2S KS 4S JS JH JD
示例2

输入

复制
2
AS AH
AC AD
AS AH
2S 2H

输出

复制
YES 2H 3S 4D 5C 6H 7S
NO
YES 2C 2D 3S 3H 4C 4D
YES AC AD 3D 4C 5H 6S
YES 2C 2D 3D 4C 5H 6S
NO