Fire Maze | ||||||
| ||||||
Description | ||||||
After escaping from Figo's chase, Severus falls into a N * M maze designed by Figo. At first, Severus is located on the grid S. Every second he can only move to the four grids that adjacent to the grid he is located on. The moment he move to any side of the maze, he will get rid of Figo. After T seconds, Figo will reach the maze. Because Figo is the designer of the maze, when Figo arrive, he can reach any grid if he want. If Severus can't leave the maze at that moment, there is no doubt that he will be caught by Figo. Figo is very cunning. In the maze he set not only walls, but also fire! After every second, the fire will spread to the four grid that adjacent to it. When a grid is on fire, certainly, Severus can not be on the grid. Can Severus escape from the maze? | ||||||
Input | ||||||
The first line will be a integer CS, indicating the number of test cases. In every case, there will be three integer N, M, T. After that there will be N * M characters, decribe the maze. The "." is a empty grid, "#" is wall, "F" is the fire, "S" is the initial grid that Severus stands on. 10 <= n , m <= 100 10 <= T <=10000 | ||||||
Output | ||||||
There is only one line, if Severus can get out, output the mininum time he need to escape from the maze. If he can't, output "Poor Severus must be caught by strong Figo!!!" | ||||||
Sample Input | ||||||
2 4 4 4 #### #SF# #..# #..# 3 3 4 ### #S. #.F
| ||||||
Sample Output | ||||||
3 Poor Severus must be caught by strong Figo!!! #include
|