Code challenge
Challenge 2 - Catch them all
Something strange has happened. All your pokemons have escaped. Can you catch them all?

You've been given a map (shown with rows and columns) so you can find all the Pokémon. The Pokémon's name can only be found horizontally. But it can be written from left to right or right to left and it can be on more than one line. Once you catch a Pokémon make sure to remove it from the map. Because each Pokémon only appears once and some Pokémon can be hidden within other Pokémon.
Input
The first line will have an Integer N, which is the number of cases for the problem. It is followed by a description of T cases. Every case has an Integer P, which is the number of Pokémon to find, an Integer R, which is the number of rows, and an Integer C, which is the number of columns. Then it has P lines with the names of each Pokémon N. And finally R lines with C characters split by an empty space.
Output
For each case, there should be a line starting with "Case #x: " followed by the result of the map without the Pokémon.
Limits
1 ≤ T ≤ 20 1 ≤ P ≤ 50 1 ≤ C, R ≤ 100 1 ≤ N ≤ 100
Sample Input
2 1 4 6 SNORLAX T A K E C A S N O R L A X R E W I T H V E N O M 2 3 10 PIKACHU CHARIZARD N O P O K E M U H C A K I C H A R I Z A R D P O N S H E R E
Sample Output
Case #1: TAKECAREWITHVENOM Case #2: NOPOKEMONSHERE
Explanation
There is a map like the table below in the first scenario.
T | A | K | E | C | A |
S | N | O | R | L | A |
X | R | E | W | I | T |
H | V | E | N | O | M |
After you find SNORLAX you have the expected result.
T | A | K | E | C | A |
R | E | W | I | T | H |
V | E | N | O | M |
There is a map like the table below in the second scenario.
N | O | P | O | K | E | M | U | H | C |
A | K | I | C | H | A | R | I | Z | A |
R | D | P | O | N | S | H | E | R | E |
You can't find PIKACHU (UHCAKIP) until CHARIZARD has been caught.
N | O | P | O | K | E | M | U | H | C |
A | K | I | P | O | N | S | H | E | R |
R |
All the Pokémon have been caught.
N | O | P | O | K | E | M | O | N | S |
H | E | R | E |
Test your code
You can test your program against both the input provided in the test phase and the input provided in the submit phase. A nice output will tell you if your program got the right solution or not. You can try as many times as you want. Be careful with extra whitespace. The output should be exactly as described.
Test your program against the input provided in the test phase
Test your program against the input provided in the submit phase
During the submit phase, in some problems, we might give your program harder inputs. As with the test token, a nice output will tell you if your program got the right solution or not. You can try as many times as you need.
In the actual contest you have to solve the test phase before you can submit your code. You must provide the source code used to solve the challenge and you can only make one submission. After your solution is submitted, you won't be able to modify it to fix issues or make it faster.
If you have any doubts, please see the info section.