from collections import deque
dx = [-1, 1, 0, 0, 0, 0]
dy = [0, 0, -1, 1, 0, 0]
dz = [0, 0, 0, 0, 1, -1]
def BFS(g, st, ed, L, R, C):
q = deque()
q.append((st[0], st[1], st[2], 0))
ans = 0x3f3f3f3f
vis = [[[0] * L for i in range(C)]for j in range(R)]
while q:
x, y, z, t = q.popleft()
if x == ed[0] and y == ed[1] and z == ed[2]: ans = min(ans, t)
for i in range(6):
nx, ny, nz = x + dx[i], y + dy[i], z + dz[i]
if nx < 0 or ny < 0 or nz < 0 or nx >= R or ny >= C or nz >= L: continue
if g[nz][nx][ny] == '#': continue
if not vis[nx][ny][nz]:
vis[nx][ny][nz] = 1
q.append((nx, ny, nz, t + 1))
return ans
while True:
L, R, C = map(int, input().split())
if L == R == C == 0: break
g = [[[]for j in range(R)]for k in range(L)]
for i in range(L):
for j in range(R):
tmp = input()
for k in range(C):
if tmp[k] == 'S': st = (j, k, i)
if tmp[k] == 'E': ed = (j, k, i)
g[i][j].append(tmp[k])
input()
ans = BFS(g, st, ed, L, R, C)
if ans > 0x3f3f3f:
print('Trapped!')
else:
print(f'Escaped in {ans} minute(s).')