You are playing Hangman with your friend Sean. And while you have heard that Sean is very good at taking candy from a baby, he is not as good at this game. Can you take advantage of Sean's imperfect strategy, and make him lose as badly as possible?
+--+
| O
| /|\ Mystery word: _ a _ a _ a _
| / \
|
+-+---+
Hangman is played as follows:
- There is a dictionary
of all valid words, which both you and Sean know. A word consists only of the charactersa
-z
. In particular, there are no spaces. - You begin by choosing any word from
, and writing it down on a blackboard with each letter replaced by a blank:_
. - On his turn, Sean can choose any letter and ask you if it is in the word. If it is, you reveal all locations of that letter. Otherwise, Sean loses a point.
- Once all letters in the word have been revealed, the round ends.
- The round never ends early, no matter how many points Sean loses.
Sean uses a very simple strategy. He makes a list
Given Sean's list, what word should you choose to make Sean lose as many as points as possible? If several choices are equally good, you should choose the one that appears first in
Example
Suppose Sean decides to guess the letters in alphabetical order (i.e., banana
, caravan
, and pajamas
. If you choose pajamas
, the game would play out as follows:
- You begin by writing 7 blanks
_ _ _ _ _ _ _
on the blackboard. Based on the number of blanks, Sean knows immediately that the word is eithercaravan
orpajamas
. - Sean begins by guessing
a
since it is first in , and you reveal all locations of the lettera
on the blackboard:_ a _ a _ a _
. - Sean skips
b
even though it is used inbanana
. Sean already knows that is not your word. - He then guesses
c
because it appears incaravan
. It does not appear in the word you actually chose though, so Sean loses a point and nothing more is revealed. - By process of elimination, Sean now knows your word has to be
pajamas
, so he proceeds to guessj
,m
,p
, ands
in order, without losing any more points.
So Sean loses one point if you choose pajamas
. He would have gotten either of the other words without losing any points.
Input Specification
The first line of the input gives the number of test cases,
The next a
- z
.
The final
Output Specification
For each test case, output one line containing Case #x: w1 w2 ... wM
, where
Limits
Each word in
No two words in
Memory limit: 1 GB.
Small Dataset
Time limit: 30 seconds.
Large Dataset
Time limit: 60 seconds.
Sample Input
2
3 2
banana
caravan
pajamas
abcdefghijklmnopqrstuvwxyz
etaoisnhrdlcumwfgypbvkjxqz
4 1
potato
tomato
garlic
pepper
zyxwvutsrqponmlkjihgfedcba
Sample Output
Case #1: pajamas caravan
Case #2: garlic
Note
This problem has different time limits for different batches. If you exceed the Time Limit for any batch, the judge will incorrectly display >60.000s
regardless of the actual time taken. Refer to the Limits section for batch-specific time limits.
Comments