注册

登陆

Card Game

Description

Earthstone is a famous online card game created by Lizard Entertainment. It is a collectible card game that revolves around turn-based matches between two opponents. Players start the game with a substantial collection of basic cards, but can gain rarer and more powerful cards through purchasing packs of additional cards, or as rewards for competing in the arena. Card packs can be purchased with gold, an in-game currency rewarded for completing random daily quests and winning matches, or by using real money in the in-game store.

Edward is the headmaster of Marjar University. He has lots of money and lots of spare time. Recent days, he was addicted to Earthstone that he bought over 400 card packs! After having purchased so many cards, he believed that he was invincible. Then, he entered the arena and started a match... Before we continue the story of Edward, let us look at the rules of Earthstone first.

Each Earthstone battle is a one on one turn-based match between two opponents. During a player's turn, he can choose to play any of his cards and command the minions to attack targets. Those played cards will be placed on the table as they are 'summoned' as minions. Each card has two basic attributes:

Attack Ai: If a minion attacks a character or was attacked, it will deal Ai points of damage to the opponent. A character whose attack value is zero cannot actively attack.

Health Hi: The minion has Hi points of initial health. After being damaged, the minion's health will decrease by the corresponding damage value. The minion will be killed and discarded if its health is less than or equal to zero.

If a minion attacks another minion, both of them will receive damage simultaneously. Besides minions, each player has a hero with some points of initial health. The hero has zero points of attack value and does not have any skills. If a player's hero is killed, he will lose the game. By the way, the word 'character' in Earthstone can mean either a hero or a minion.

Apart from the two basic attributes, minions may have zero or more following abilities:

Charge: A minion cannot actively attack on the same turn that it is summoned, unless it has the Charge ability.

DivineShield: Absorbs the first time of non-zero damage taken by the minion, removing the shield.

Taunt: Enemies must attack minions with Taunt before any non-Taunt characters.

Windfury: During a player's turn, the player can command all his existing minions or newly summoned Charge minions to attack enemy characters for at most one time. But if a minion has the Windfury ability, it can attack twice instead of once.

Now, let us come back to the story of Edward. Edward is playing the game and it is Edward's turn now. There are already X + Y minions on the table. X of them are on the Edward's side and the other minions are fighting for the opponent. Besides the existing minions, Edward has Z cards in his hand. The health of opponent's hero is M. There is no limitation about the number of cards can be played on a turn or the maximal number of minions on the table.

Edward is a cautious man, he wants you find out a long-term game strategy about the current situation. You need to reduce the potential damage received on the next turn (the opponent's turn). The potential damage is defined as the sum of attack value of the opponent's minions, with Windfury minions count twice. If there are multiple solutions, please find out the solution which can deal as many as possible points of damage to the opponent's hero. But, Edward will also not miss any chance to win the game. If there exists a strategy to kill the opponent's hero within the current turn, he will use the winning strategy instead.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The following lines of input consists of 3 parts. These parts have the same input format and contain X, Y, Z lines respectively. Each line describes a minion or a card, in the format of "Ai/Hiabilities" (0 <= Ai <= 12, 1 <= Hi <= 15). The abilities contains zero or more ability names, separated by a space.
There is no space after Hi if the abilities is empty.

Output

For each test case, output the minimal potential damage and the maximal damage that Edward can deal to the opponent's hero.

If the opponent's hero can be killed within the current turn, output "Well played" instead (without quotes).