The Repeater (Large)
InterviewTime limit5sMemory limit512 MB
Decide whether N lowercase strings can be made identical by duplicating or deleting adjacent equal letters, and report the fewest moves.
Problem
Fegla and Omar play games every day. They are bored with every game they know, so they invented one of their own and called it "The Repeater".
It is a game for two players. Fegla writes down strings. Omar has to make all the strings identical using the smallest possible number of moves, and he may use zero moves. Only these two moves are allowed.
- Pick any character in any of the strings and repeat it, adding another copy of that character directly after it. For example, one move changes "abc" into "abbc" by repeating the character '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", but it cannot change it 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 round.
Help Omar win: decide whether the given strings can be made identical, and if they can, report 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 holding the number of strings , followed by lines with one string each. Every string is non-empty and consists of lower case English letters 'a' to 'z' only.
Limits
- The length of each string is at least 1 and at most 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 all the strings identical. If there is no way to make them identical, print Fegla Won in place of .