Woburn ECOO 1998

Wheel of Fortune

INPUT FILE: wheel.in
OUTPUT FILE: wheel.out

Two players, A and B, play Wheel of Fortune - A always goes first. The object of the game is to reveal a hidden phrase (length <= 200).

The rules are:
a) if a player selects a consonant and it is in the phrase, ALL occurrences of the letter are uncovered and the player is paid (# of occurrences)*(worth of letter).
b) If a player selects a vowel (a, e, i, o, u) a flat fee of $200 is subtracted and ALL occurrences of the letter are uncovered. (the player pays $200, no matter if/how many times the letter occurs)
c) if the letter selected is not in the phrase, the player loses his turn.
d) the game ends when the letter selected is an asterisk. The player with the current turn is the winner.

NOTE: the inputs will always be valid (e.g., a letter will not be selected twice, players money will not go below 0, etc.)

You must simulate a game of Wheel of Fortune and output the final scores and board position.

INPUT
The first line contains the number of test cases.
For each test case:

The first line contains the phrase to be guessed, a string of letters and/or spaces in uppercase.
The second line contains X, the number of turns (guesses) in the game.
On each of the next X lines is the letter the player whose turn it is guessed, followed by the amount they spun on the wheel (or an asterisk if they chose a vowel).

OUTPUT
For each test case, write to the output the winning player, the amount of money they collected, and the phrase at the end of the game with guessed letters revealed and unguessed ones marked by "?".

Sample Input File

1
COMMEMORATIVE COIN
7
T
200
H
400
M
300
O
200
S
500
C
350
*
0

Output for Sample Input

A
900
COMM?MO??T??? CO??
Downloader failed! Response object 006~ASP 0159~Buffering Off~Buffering must be on.