import sys
from collections import deque
dy = (0, 1, 0, -1, 0, 0)
dx = (1, 0, -1, 0, 0, 0)
dz = (0, 0, 0, 0, 1, -1)
def is_invalid_range(z, y, x):
return z < 0 or y < 0 or x < 0 or z >= L or y >= R or x >= C
def bfs(z, y, x):
q = deque([[z, y, x]])
lst[z][y][x] = '.'
visit = [[[0] * C for _ in range(R)] for _ in range(L)]
visit[z][y][x] = 1
cnt = 0
while q:
cnt += 1
for _ in range(len(q)):
z, y, x = q.popleft()
for d in range(6):
nz = z + dz[d]
ny = y + dy[d]
nx = x + dx[d]
if is_invalid_range(nz, ny, nx):
continue
if visit[nz][ny][nx]:
continue
if lst[nz][ny][nx] == '#':
continue
if lst[nz][ny][nx] == 'E':
return cnt
visit[nz][ny][nx] = 1
q.append(([nz, ny, nx]))
return -1
while True:
L, R, C = map(int, input().split())
if L == R == C == 0:
break
sz, sy, sx = -1, -1, -1
lst = [[[''] * C for _ in range(R)] for _ in range(L)]
for i in range(L):
for j in range(R):
tmp = list(input().strip())
for k in range(C):
lst[i][j][k] = tmp[k]
if tmp[k] == 'S':
sz, sy, sx = i, j, k
input()
ans = bfs(sz, sy, sx)
if ans == -1:
print('Trapped!')
else:
print(f'Escaped in {ans} minute(s).')