The Repeater
InterviewTime limit5sMemory limit512 MB
Equalize N lowercase strings using only adjacent duplicate insertions and deletions with the fewest moves, or report impossibility.
Problem
Fegla and Omar play games every day. They got bored of every game they knew, so they invented a new one and named it "The Repeater".
It is a game for two players. Fegla writes down strings. Omar has to make all of the strings identical using only the two moves below, and he has to use as few moves as possible, possibly 0 moves.
- Pick any character in any of the strings and repeat it, adding one more copy of that character directly after it. For example, one move changes "abc" into "abbc" by repeating the 'b'.
- Pick any two adjacent identical characters in any of the strings and delete one of them. For example, one move changes "abbc" into "abc" by deleting one 'b', but it cannot change "abbc" into "bbc".
The two moves are independent. A move of the first type does not have to be followed by a move of the second type, and the other way around.
Help Omar win. Write a program that decides whether the strings can be made identical and, when they can, reports the minimum number of moves.
Input
The first line contains the number of test cases . test cases follow. Each test case starts with a line containing the number of strings , followed by lines with one string per line. Each string is non-empty and consists of lower case English letters 'a' to 'z' only.
Limits
- The length of each string is between 1 and 100
Output
For each test case, print one line in the form "Case #x: y", where is the test case number starting from 1 and is the minimum number of moves that makes the strings identical. If the strings cannot be made identical, print Fegla Won in place of . Do not print the double quotes.