The Sangbeom Building

No attempts yetTime limit1sMemory limit128 MB

Problem

You are trapped inside the Sangbeom Building. What is the fastest way to escape?

The building is made up of unit cubes, each with side length $1$. Every cube is either filled with gold (impassable) or empty (passable). From your current cell you can move to any of the $6$ adjacent cells (east, west, south, north, up, down), and each move takes $1$ minute. Diagonal moves are not allowed. The outer surface of the building is entirely blocked by gold, so you can only leave through an exit.

Can you escape the Sangbeom Building? If so, how long will it take?

Input

The input consists of several test cases. Each test case begins with three integers $L$, $R$, and $C$. $L,(1 \le L \le 30)$ is the number of floors of the building, and $R,(1 \le R \le 30)$ and $C,(1 \le C \le 30)$ are the number of rows and columns on each floor.

After that, $R$ rows of $C$ characters each are given for every one of the $L$ floors. Each character represents one cell of the building:

  • # : a cell blocked by gold that cannot be passed
  • . : an empty cell that can be passed
  • S : your starting position
  • E : the exit through which you can escape

There is one blank line between consecutive floors. There is always exactly one starting position and exactly one exit. The end of the input is marked by a line in which $L$, $R$, and $C$ are all $0$; this line is not processed.

Output

For each building, output the answer on its own line. If you can escape, print:

Escaped in x minute(s).

where x is the minimum time in minutes needed to escape the building. If escaping is impossible, print:

Trapped!