URI Online Judge | 1840

The Prisoner of Azkaban

By Leandro Zatesko, UFFS BR 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:

4 5 6 7 Q J K A 2 3

♦  ♠  ♥  ♣


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}.


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