Deck of Cards

Two players alternate playing a card matching the table card in color or value; the first unable to move loses, so find the winner under optimal play.

Medium7Game theoryGraphDFSBacktrackingInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Malcolm and Richard are the last two players left in a card game. Every card carries one colour and one numeric value. The colour is R, G, B or Y, and the value runs from 1 to 9. A hand may hold several copies of the same card.

The players take turns, and on each turn the player to move plays one card from their hand. The card played must match the previous card on the table in colour or in numeric value, and matching both is allowed. The first player who has no playable card loses. That is, a player loses when no card in their hand shares a colour or a numeric value with the card on the table.

Each player sees the other player's hand, so nothing is hidden. Malcolm plays first. Given both hands and the card currently on the table, determine who wins when both players play optimally.

Input

The first line contains two integers mm and rr (1m10001 \le m \le 1000, 1r10001 \le r \le 1000), the number of cards in Malcolm's hand and the number of cards in Richard's hand.

The second line contains mm strings describing the cards in Malcolm's hand. Each card is a colour character, one of R, G, B or Y, followed by a numeric value from 1 to 9.

The third line contains rr strings describing the cards in Richard's hand, written in the same format.

The fourth line contains one string describing the card currently on the table, written in the same format.

Output

Print the name of the winner when both players play optimally, either Malcolm or Richard.