You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is made up of unit cube rooms, which may or may not be accessible. It takes one minute to move one unit north, south, east, west, up, or down. You cannot move diagonally, and the maze is surrounded on all sides by solid rock.
Is it possible to escape from the dungeon? If so, how long will it take?
The input consists of several dungeons. Each dungeon description starts with a line containing three integers , , and (all not exceeding ).
is the number of levels in the dungeon.
and are the number of rows and columns for each level's plan.
Then blocks follow, each containing lines of characters, describing a level. Each character describes one cell in the dungeon. Cells filled with solid rock are represented by the character #, empty cells by .. Your starting position is indicated by S and the exit by E. Each dungeon description is separated by a blank line. The input ends with three zeroes.
For each dungeon, print one line. If it is possible to reach the exit, print:
Escaped in X minute(s).
where is the minimum time needed to escape.
If escape is not possible, print:
Trapped!
Example 1