Bora Bora is a simple card game for children, named after the South Pacific island where it was invented. Two or more players play with a standard deck of cards. Every card has a rank -- Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King -- and one of four suits: Clubs, Diamonds, Hearts, or Spades.
Players sit in a circle and take turns. Depending on the cards played, the next player may be the one to the left (clockwise) or to the right (counter-clockwise) of the current player. Play starts in the clockwise direction.
The deck is shuffled and each player is dealt a hand. The rest of the deck is placed face down on the table as the stock pile. The top card of the stock is then turned face up to start the discard pile.
The goal is to be the first to get rid of every card in your hand. On each turn a player discards at most one card. A card may be discarded only if it has the same rank or the same suit as the current top card of the discard pile; the discarded card becomes the new top card. If a player has no playable card, he draws one card from the stock: if that drawn card can be discarded he discards it immediately, otherwise he keeps it and his turn ends.
When a player can discard, he always discards the highest-valued playable card. A card's value is determined first by its rank (Ace is lowest, King is highest) and then by its suit, ordered from lowest to highest as Clubs, Diamonds, Hearts, Spades. Thus the King of Spades is the highest card and the Ace of Clubs the lowest; for example, the Queen of Diamonds outranks any Jack but is below the Queen of Hearts.
Some discarded cards change the flow of play:
The effect of the very first discard-pile card (the one flipped from the stock at the start) applies to the first player. For example, if the first player is $p$ and the starting card is an Ace, then $p$ draws one card and discards nothing on his first turn. If the starting card is a Queen, the direction reverses to counter-clockwise but the first player remains the same.
The winner is the first player to discard their last card; the game ends immediately at that point.
Given the shuffled deck and the number of players, determine who wins.
The input contains several test cases. The first line of a test case has three integers $P$, $M$ and $N$ separated by single spaces: the number of players ($2 \le P \le 10$), the number of cards dealt to each player at the start ($1 \le M \le 11$), and the total number of cards in the shuffled deck ($3 \le N \le 300$). Each of the next $N$ lines describes one card as an integer $X$ and a character $S$ separated by one space, giving the card's rank and suit. Ranks map to integers 1 to 13 (Ace is 1, Jack is 11, Queen is 12, King is 13). Suits are given by their initial letter: C (Clubs), D (Diamonds), H (Hearts), or S (Spades).
Players are numbered 1 to $P$ and sit in a circle in clockwise order $1, 2, \dots, P, 1$. The first $P \times M$ cards of the deck are dealt to the players: the first $M$ cards to player 1, the next $M$ to player 2, and so on. The next card -- the $(P \times M + 1)$-th -- starts the discard pile, and the remaining cards form the stock. The $(P \times M + 2)$-th card is the top of the stock (the first to be drawn) and the $N$-th card is the bottom (the last that can be drawn). Player 1 always plays first, even when the starting discard card is a Queen. Every test case has exactly one winner, and the deck always has enough cards to finish the game.
The end of input is a line containing only three zeros separated by single spaces.
For each test case, print a single line containing the number of the player who wins the game.