Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 65536/32768 K (Java/Others)

Consider this simple form of shuffling a deck of cards. Hold the deck face down and count to a certain number (say k), on each count taking one card from the top of the deck and placing it at the bottom. When you have finished counting, turn the top card (the k+1'th card) over and place it face up on the table. Thus cards are continually moved from the top of the deck to the bottom, even when you have fewer cards than your chosen number. Continue in this way until you have no more cards left. Thus if k was 4, you would move 4 cards, one by one, from the top of the deck to the bottom and turn over the fifth. You would then move the sixth, seventh, eighth and ninth cards to the bottom and expose the tenth. Note that the number of the exposed card is always one more than k; if k was nine you would expose every tenth card, and so on.

Write a program that will read in the chosen number (k) and details of a deck of cards and simulate this process. Remember that a standard deck (or pack) of cards contains 52 cards. These are divided into 4 suits - Spades, Hearts, Diamonds and Clubs. Within each suit there are 13 cards - Ace (A), 2-9, Ten (T), Jack (J), Queen (Q) and King (K).

Write a program that will read in the chosen number (k) and details of a deck of cards and simulate this process. Remember that a standard deck (or pack) of cards contains 52 cards. These are divided into 4 suits - Spades, Hearts, Diamonds and Clubs. Within each suit there are 13 cards - Ace (A), 2-9, Ten (T), Jack (J), Queen (Q) and King (K).

Input will consist of a series of scenarios. Each scenario will start with a number k (4 <= k <= 26) on a line by itself. This will be followed by the description of a deck. A deck will be specified on four lines with 13 cards on each line and with cards separated by exactly one space (see the example below). The cards are shown as they would be seen if they were face up, thus the last card in the sequence would be the top of the deck as far as you are concerned. The file will be terminated by a line consisting of a zero (0).

Output will consist of a series of lines, one for each scenario in the input. Each line will consist of the last card played, in the format shown below.

提交代码