A simple color-matching game for children is played on a board that is a single row of colored squares. Every player has one piece, and all pieces begin at START, just before the first square.
Players take turns in a fixed order — Player 1, then Player 2, and so on — each drawing the next card from a deck. A card shows either one colored square or two colored squares of the same color. On their turn a player moves their piece forward:
A player wins the instant their piece lands on the last square. It is possible for the whole deck to be drawn without anyone winning.
Colors are written as capital letters A–Z. Here is an example board (the leftmost square is the START side, the rightmost square is the FINISH side):
| R | Y | G | P | B | R | Y | G | B | R | P | O | P |
Consider the deck R, B, GG, Y, P, B, P, RR. With 3 players the game proceeds as follows:
R and moves to the 1st square.B and moves to the 5th square.GG and moves to the 8th square.Y and moves to the 2nd square.P and moves to the 11th square.B and moves to the 9th square.P and moves to the 4th square.RR and wins — there is no R ahead of the piece, so it advances to the last square.Using the same board and deck with 2 players, Player 1 wins after 7 cards. With 4 players, no one wins after the deck of 8 cards is exhausted.
The input contains one or more games. Each game starts with a line of three integers: the number of players (1–4), the number of squares on the board (1–79), and the number of cards in the deck (1–200). The next line is a string of capital letters listing the board's square colors, one letter per square, from the START side to the FINISH side. The following lines are the deck — one card per line, in the order they are drawn — where each card is a single capital letter or the same capital letter written twice.
The input ends with a line whose first value is 0 (zero players); the other two values on that final line are present but meaningless.
For each game, print exactly one line:
Player X won after N cards., where X is the winning player's number and N is the total number of cards drawn (including the winning card).No player won after N cards., where N is the number of cards in the deck.Always use the plural word "cards", even when N is 1.