ZOJ Problem Set - 3459
The 24-Point-Game is such a famous game that almost everyone know its name. The rule of the 24-Point-Game is simple: given 4 poker cards, the player should use the Four Arithmetic Operations("+", "-", "*" and "/") to make the numbers of the four cards to 24.
For example, given four cards whose numbers are 1, 2, 3 and 9, you can give an answer 2*1*(9+3)=24 or another solution 3*9-1-2=24.
One day, two famous roles in the popular card game called SanGuoSha, Sima Yi and Zhang Jiao, would like to play the 24-Point-Game. To judge who is smarter, they add some rules to the game.
In the beginning of the game, there are 4 cards in the public place, also, Sima Yi and Zhang Jiao hold some cards respectively. Then, they process the game in turn. In Sima Yi's turn, he can use one of his card to replace a card in the public place, and then he loses the card he uses. In Zhang Jiao's turn, he can use one of his black colored card to exchange with one of the cards in the public place. That's, Zhang Jiao can use a black colored card to change a card in the public place, and gets the card changed.
Sima Yi will take the first turn. The two players can choose to change or not to change the public cards in their own turn, and if he doesn't change the public cards, the game is terminated immediately, except for the first turn.(That's to say, in the beginning, if Sima Yi doesn't change a public card, the game continues, and turns to Zhang Jiao's turn.) At last, if Sima Yi can calculate 24 based on the cards in the public place, he wins, otherwise Zhang Jiao wins.
Assume that the two men are clever enough, your task is to find the winner of the game.
There are multiple test cases. The first line of input is an integer T(1 ≤ T ≤ 23), indicating the number of test cases. Then T cases follow. The first line of each cases is n1, c1, n2, c2, n3, c3, n4, c4, where ni and ci are the number and the color in the ith card. There are only two colors red and black, respectively represented by the letter "r" and "b". The second line of each cases is two integers n and m(1 ≤ n, m ≤ 6), indicating the number of cards held by Sima Yi and Zhang Jiao. The third line is the imformations of the cards held by Sima Yi in specification n1 c1 n2 c2 ... nn cn. Then follows the last line in specification n1 c1 n2 c2 ... nm cm, indicating the imformations of the cards held by Zhang Jiao. All numbers in the cards are integers and range form 1 to 10.
For each case, output a single line a string in specification X Wins!, where X is the winner of the game.
2 1 r 1 r 1 r 1 b 1 1 1 r 1 b 3 b 1 b 1 r 8 r 2 2 5 r 9 r 6 r 4 b
Zhang Jiao Wins! Sima Yi Wins!
Author: LI, Dinghua
Contest: ZOJ Monthly, January 2011