{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tSnooker is a cue sport that is played on a large baize-covered table with pockets in each of the four corners and in the middle of each of the long side cushions. It is played using a cue and snooker balls: one white cue ball, 15 red balls worth one point each, and six balls of different colors: yellow (2 points), green (3), brown (4), blue (5), pink (6) and black (7). A player (or team) wins a frame (individual game) of snooker by scoring more points than the opponent(s), using the cue ball to pot the red and colored balls.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tIn this problem, your job is the referee of snooker. You should score both players, ask the correct player to play next, as well as place some of the balls back to the table if necessary. The rules of snooker needed for this problem are following. (We ignore some fouls about incorrectly hitting the cue ball here. We assume that the cue ball is never snookered after a foul, so \u003cem\u003efree ball\u003c/em\u003e will never occur. We also assume that both players will make their best attempts to hit the ball on, so you do not need to declare a \u003cem\u003emiss\u003c/em\u003e when they do not hit the ball on first.)\u003c/p\u003e\r\n\u003cp align\u003d\"center\"\u003e\r\n\t\u003cimg alt\u003d\"Snooker\" height\u003d\"379\" longdesc\u003d\"Snooker\" src\u003d\"http://acmicpc-live-archive.uva.es/nuevoportal/data/p5014.png\" width\u003d\"720\" /\u003e\u003c/p\u003e\r\n\u003cp\u003e\r\n\tAt the beginning of each frame the balls are set up by the referee as illustrated above. This will be followed by a \u003cem\u003ebreak-off shot\u003c/em\u003e, the white cue ball can be placed anywhere inside the D (it is called \u003cem\u003ein-hand\u003c/em\u003e, which also happens when the cue ball is potted).\u003c/p\u003e\r\n\u003cp\u003e\r\n\tPlayers take turns in visiting the table. A \u003cem\u003ebreak\u003c/em\u003e is the number of points scored by a player in one single visit to the table. A player\u0026#39;s turn and break end when he fails to pot a ball, when he does something against the rules of the game, which is called a \u003cem\u003efoul\u003c/em\u003e, or when a frame has ended.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tThe ball or balls that can be hit first by the white are called the ball(s) \u0026quot;on\u0026quot; for that particular stroke. The ball(s) \u0026quot;on\u0026quot; differ from shot to shot: a red ball, if potted, must be followed by a color, and so on until a break ends; if a red is not potted, any red ball remains the ball \u0026quot;on\u0026quot;. Only a ball or balls \u0026quot;on\u0026quot; may be potted legally by a player. If a ball not \u0026quot;on\u0026quot; is potted, this is a foul.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tThe game of snooker generally consists of two phases. The first phase is the situation in which there are still red balls on the table. In the first phase, at the beginning of a player\u0026#39;s turn, the balls \u0026quot;on\u0026quot; are all remaining red balls. The player must therefore attempt to first hit and pot one or more red balls. For every red ball potted, the player will receive 1 point. When a red has been potted, it will stay off the table and the player can continue his break. If no red has been potted or a foul has been made, the other player will come into play.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tIn case one or more red balls have been potted, the player can continue his break. This time one of the six colors (yellow, green, brown, blue, pink and black) is the ball \u0026quot;on\u0026quot;. Only one of these can be the ball \u0026quot;on\u0026quot; and the rules of the game state that a player must nominate his desired color to the referee, although it is often clear which ball the striker is playing and it is not necessary to nominate.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tWhen the nominated color is potted, the player will be awarded the correct number of points (yellow, 2; green, 3; brown, 4; blue, 5; pink, 6; black, 7). The color is then taken out of the pocket by the referee and placed on its original spot.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tBecause only one of the colors is the ball \u0026quot;on\u0026quot;, it is a foul to first hit multiple colors at the same time, or pot more than one color.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tIf a player fails to pot a ball \u0026quot;on\u0026quot;, it being a red or nominated color, the other player will come into play and the balls \u0026quot;on\u0026quot; are always the reds, as long as there are still reds on the table.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tThe alternation between red balls and colors ends when all reds have been potted and a color is potted after the last red, or a failed attempt to do so is made. Then the second phase begins. All six colors have to be potted in ascending order of their points value (yellow, green, brown, blue, pink, black). Each becomes the ball \u0026quot;on\u0026quot; in that order. During this phase, when potted, the colors stay down and are not replaced on the table, unless a foul is made when potting the color, in which case the color is respotted.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tWhen only the black is left, the first score or foul ends the frame, and the player who has scored most points has won it. However, if the score is tied after that, the black is respotted, the players draw lots for choice of playing, the next player plays from in-hand, and the next score or foul ends the frame.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tWhen a foul is made during a shot, the player\u0026#39;s turn is ended and he will receive no points for the foul shot. The other player will receive penalty points. Colors illegally potted are respotted (while reds are not), and if the cue ball is potted, the next player will play from in-hand. Fouls concerned in this problem are:\u003c/p\u003e\r\n\u003cul\u003e\r\n\t\u003cli\u003e\r\n\t\tfailing to hit any other ball with the cue ball\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\tfirst hitting a ball \u0026quot;not-on\u0026quot; with the cue ball\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\tpotting a ball \u0026quot;not-on\u0026quot;\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\tpotting the white (in-off)\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003e\r\n\tPenalty points are at least 4 points and at most 7 points. The number of penalty points is the value of the ball \u0026quot;on\u0026quot;, or any of the \u0026quot;foul\u0026quot; balls, whichever is highest. When more than one foul is made, the penalty is not the added total - only the most highly valued foul is counted. As players usually do not nominate a color explicitly when hitting the colors, please be tolerant and assume that he always nominate the ball with the lowest score when it cannot be deduced from the ball first hit (i.e. when the cue ball does not hit any ball or hit a red first).\u003c/p\u003e\r\n\u003cp\u003e\r\n\tIf a player commits a foul, and his opponent considers that the position left is unattractive, he may request that the offender play again from the resulting position.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tThe input file contains multiple test cases. The first line of the input file is a single integer \u003cem\u003e\u003cstrong\u003eT\u003c/strong\u003e\u003c/em\u003e (\u003cem\u003e\u003cstrong\u003eT\u003c/strong\u003e\u003c/em\u003e \u0026le; 200), the number of test cases.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tFor each test case (frame), the first line contains the names of the two players separated by a whitespace. The first player will take the break-off shot. Each name is made up of no more than 20 English letters, and the two names are different.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tAfter that, the input mainly consists of lines that describe a stroke each (with two exceptions stated later). A stroke is described by the color of the ball first hit by the cue ball (or \u0026quot;None\u0026quot; if the cue ball does not hit any ball), followed by zero or more colors of the balls potted, all separated by whitespaces. For example, a line \u0026quot;Red Red White Red\u0026quot; means the cue ball first hit a red ball, and 2 reds are potted as well as the cue ball itself; and a line \u0026quot;None\u0026quot; means the cue ball does not hit any ball thus no ball is potted. You can assume that all strokes are legal according to the balls remain on the table, and the cue ball will not hit two or more ball first simultaneously.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tA line \u0026quot;Play again\u0026quot; may appear if and only if the last stroke is a foul. It means the other player request that the offender play again from the resulting position.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tIf a score or foul occurs when only the black is left, and the score is tied after that, a line with either player\u0026#39;s name will follow. That means the player will play next as a result of the lot.\u003c/p\u003e\r\n\u003cp\u003e\r\n\tThe case end when the frame ends. There is a blank line before every test case.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e\r\n\tFor each frame, print a line in the format \u0026quot;Frame \u003cem\u003eK\u003c/em\u003e\u0026quot; first, where \u003cem\u003eK\u003c/em\u003e is the index of this case starts from 1. Then use the output to indicate the referee\u0026#39;s behaviors:\u003c/p\u003e\r\n\u003cul\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tWhen a frame begins, print a line in the format \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn, in-hand\u0026quot;, where \u003cem\u003ePlayerName\u003c/em\u003e is the name of the player who take the break-off shot.\u003c/p\u003e\r\n\t\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tAfter each stroke, print a line \u0026quot;Foul!\u0026quot; first if it is a foul. Then print a line with current score in the format \u0026quot;\u003cem\u003eScoreA\u003c/em\u003e : \u003cem\u003eScoreB\u003c/em\u003e\u0026quot;, where \u003cem\u003eScoreA\u003c/em\u003e is the score of the player who take the break-off shot, and \u003cem\u003eScoreB\u003c/em\u003e is the other player\u0026#39;s score.\u003c/p\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tAfter that, if the frame continue fairly (i.e. not only black is left before the stroke, or it is not a score or foul when only black is left), and some ball(s) should be respotted. Print a line with the word \u0026quot;Respot\u0026quot; following by the color(s) of the ball(s), all separated by whitespace. If more than one ball should be respotted, print their colors in ascending order of their values. Do not print anything if no ball needed to be respotted.\u003c/p\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tAt last (when the frame continue fairly and any necessary ball has been respotted), if the last player\u0026#39;s break ends, print a line in the format \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn\u0026quot; to ask the other player to play next, where \u003cem\u003ePlayerName\u003c/em\u003e is the next player\u0026#39;s name. If the next player should play from in-hand, print \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn, in-hand\u0026quot; instead.\u003c/p\u003e\r\n\t\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tAfter a foul, if the other player request that the offender play again, just print a line \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn\u0026quot; or \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn, in-hand\u0026quot; according to whether the cue ball is in-hand, where \u003cem\u003ePlayerName\u003c/em\u003e is the offender\u0026#39;s name. Note that the requester is actually requesting in his turn, after you asked him to play next.\u003c/p\u003e\r\n\t\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tIf a score or foul occurs when only the black is left, and the score is tied after that, print a line \u0026quot;Tie\u0026quot; after the score. Then print two lines \u0026quot;Respot Black\u0026quot; and \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e\u0026#39;s turn, in-hand\u0026quot; to respot the black and play from in-hand, where \u003cem\u003ePlayerName\u003c/em\u003e is the next player\u0026#39;s name (determined by the lot).\u003c/p\u003e\r\n\t\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003cp\u003e\r\n\t\t\tWhen the frame ends, print a line \u0026quot;\u003cem\u003ePlayerName\u003c/em\u003e wins\u0026quot; after the score, where \u003cem\u003ePlayerName\u003c/em\u003e is the winner\u0026#39;s name.\u003c/p\u003e\r\n\t\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003e\r\n\tPrint a blank line between every two successive cases.\u003c/p\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e1\r\n\r\nZero Maxbreak\r\nRed White\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nRed Red\r\nBlack Black\r\nYellow Yellow\r\nGreen Green\r\nBrown Brown\r\nBlue Blue\r\nPink Pink\r\nBlack Black\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003eFrame 1\r\nZero\u0026#39;s turn, in-hand\r\nFoul!\r\n0 : 4\r\nMaxbreak\u0026#39;s turn, in-hand\r\n0 : 5\r\n0 : 12\r\nRespot Black\r\n0 : 13\r\n0 : 20\r\nRespot Black\r\n0 : 21\r\n0 : 28\r\nRespot Black\r\n0 : 29\r\n0 : 36\r\nRespot Black\r\n0 : 37\r\n0 : 44\r\nRespot Black\r\n0 : 45\r\n0 : 52\r\nRespot Black\r\n0 : 53\r\n0 : 60\r\nRespot Black\r\n0 : 61\r\n0 : 68\r\nRespot Black\r\n0 : 69\r\n0 : 76\r\nRespot Black\r\n0 : 77\r\n0 : 84\r\nRespot Black\r\n0 : 85\r\n0 : 92\r\nRespot Black\r\n0 : 93\r\n0 : 100\r\nRespot Black\r\n0 : 101\r\n0 : 108\r\nRespot Black\r\n0 : 109\r\n0 : 116\r\nRespot Black\r\n0 : 117\r\n0 : 124\r\nRespot Black\r\n0 : 126\r\n0 : 129\r\n0 : 133\r\n0 : 138\r\n0 : 144\r\n0 : 151\r\nMaxbreak wins\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cp\u003e\r\n\t\u003cem\u003eReference:\u003c/em\u003e\u003c/p\u003e\r\n\u003cul\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003ca href\u003d\"http://en.wikipedia.org/wiki/Rules_of_snooker\"\u003e\u003cem\u003e http://en.wikipedia.org/wiki/\u003c/em\u003e\u003cem\u003eRules_of_snooker\u003c/em\u003e\u003c/a\u003e\u003cem\u003e (source of image)\u003c/em\u003e\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003ca href\u003d\"http://www.worldsnooker.com/rules_of_snooker.htm\"\u003e \u003cem\u003ehttp://www.worldsnooker.com/rules_of_snooker.htm\u003c/em\u003e\u003c/a\u003e\u003c/li\u003e\r\n\t\u003cli\u003e\r\n\t\t\u003ca href\u003d\"http://www.billiardworld.com/snooker.html\"\u003e\u003cem\u003ehttp://www.billiardworld.com/snooker.html\u003c/em\u003e\u003c/a\u003e\u003c/li\u003e\r\n\u003c/ul\u003e"}}]}