URI Online Judge | 1840

# The Prisoner of Azkaban

By Leandro Zatesko, UFFS Brazil

Timelimit: 1

In 1950, four men were arrested, accused of setting fire to the church of Chapecó. Whether they were guilty indeed no one will ever know, but the rage of the people is always faster in judging than the courts. Worried about maintaining the physical integrity of the prisoners, the police chief intended to transfer them to Azkaban. “They will be safer in the hands of the dementors than in the hands of the people of Chapecó”, he declared while making the arrangements with the Minister of Magic for the transfer, scheduled for the next morning.

While the prisoners were waiting sleepless for the transfer which would never occur, they decided to play Dammit, a very popular game in Brazil. In one of its many versions, the rules of the game are:

• Only 40 cards of a traditional french pack with 52 cards are used, discarding all cards with number 8, 9 or 10. The basic ascending ordering of the ranks used in Dammit is:

4 5 6 7 Q J K A 2 3

• One of the players deals n cards to each player. Then, this player flips a card on the table, which determines the trumps of the game, which are the cards with rank immediately above the rank of the flipped card in the basic ordering. For example, if a card with rank 7 is flipped, the cards defined as the trumps of the game are Q♦, Q♠, Q♥ and Q♣. If a card with rank 3 is flipped, the trumps are 4♦, 4♠, 4♥ and 4♣. The trumps of a match worth more than any other card. Although the suit does not interfere in the value of non-trump cards, among trumps the ascending ordering of value of the suits are:

♦  ♠  ♥  ♣

• Once the trumps of a match are defined, each player must say how many of the n rounds he thinks he will make. All players must declare their guesses even before the start of the rounds. Then begin the rounds, in each of which each player plays one of his cards revealing it on the table. A player is said to make a round if the card he plays in that round is of greater value than all the other cards played in that round. Since the suits undo a tie only among trumps, it is possible for a round not to be made by any player.
• At the end of the game, each player scores as many points as the difference between the number of rounds he said he would make and the number of rounds he has actually made. The player with lowest score wins.

## Input

The first line of the input informs the integer n (1 ≤ n ≤ 9), followed by the card flipped on the table in the beginning of the match. Each one of the 4 following lines informs the name of a player, followed by an integer m (0 ≤ mn), which represents the number of rounds the player declared he would make in the beginning of the match. The ordering in which the players are informed is always the same as they play in each round. Follow at last n lines, in a manner that the i-th of these lines informs the 4 cards played in the i-th round, in the ordering in which the cards were played. Each card is informed under the format XY, with X ∈ {4, 5, 6, 7, Q, J, K, A, 2, 3}, Y ∈ {D, S, H, C}, and D, S, H and C corresponding respectively to the suits ♦, ♠, ♥ and ♣. Consider that the name of each player consists of at least 1 and at most 10 characters of the set {a, b, …, z, A, B, …, Z}.

## Output

Print a line containing only the name of the winner of the match. If it is not possible to define a single winner for the match, print a line containing only the character star (*).

 Input Samples Output Samples 3 4H Ivo 3 Romano 2 Orlando 0 Armando 1 2C 3S JD 6H 2H KS 7D 4C 5C 7C QH 5D Orlando