Thirty-One is a game once favored by card sharps riding the trains. It uses a pack of 24 cards: four each of the cards labeled 1, 2, 3, 4, 5, and 6. Both players can see every card in the pack. The two players take turns drawing one card at a time from the pack and adding it to a single shared pile.
When a player adds a card to the pile, the total of all cards in the pile must not exceed 31. A player who is forced to make the total exceed 31 loses, and the other player wins.
Given the order in which the two players have drawn their cards so far, determine which player ultimately wins. Assume that, from that point on, both players use a perfect strategy with the remaining cards.
For example, suppose the two players draw cards in this order (the first player, then the second, alternating):
After these draws the pile totals 31. It is now Player 1's turn, and whatever card Player 1 draws pushes the total above 31, so Player 1 loses and Player 2 wins.
The input consists of several lines. Each line is one game: a string of digits, where each digit is a drawn card. Reading left to right, the first digit is the card drawn by player A, the second digit is the card drawn by player B, and the draws continue to alternate in this A, B, A, B order.
For each game, both players continue with a perfect strategy from the given position, and you must decide who wins.
For each game, print the given sequence of drawn cards and the final winner of the game (A or B), separated by a single space, on its own line.