#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int L, R, C;
const int N = 110;
typedef struct point {
int x, y, z;
}point;
point start, END;
int dis[N][N][N];
char g[N][N][N];
int bfs() {
queue<point> q;
q.push(start);
memset(dis,-1,sizeof dis);
dis[start.x][start.y][start.z] = 0;
while (q.size()) {
auto t = q.front();
q.pop();
int dx[] = {1,-1,0,0,0,0};
int dy[] = {0,0,1,-1,0,0};
int dz[] = {0,0,0,0,1,-1};
for (int i = 0; i < 6; i++) {
int X = dx[i] + t.x;
int Y = dy[i] + t.y;
int Z = dz[i] + t.z;
if (dis[X][Y][Z] != -1)continue;
if (g[X][Y][Z] == '#')continue;
if (X<=0 || X>L || Y<=0 || Y>R || Z<=0 || Z>C)continue;
dis[X][Y][Z] = dis[t.x][t.y][t.z] + 1;
if (END.x == X && END.y == Y && END.z == Z)return dis[X][Y][Z];
q.push({ X,Y,Z });
}
}
return -1;
}
int main()
{
while (1) {
scanf("%d%d%d",&L,&R,&C);
if (L == 0 && R == 0 && C == 0) {
break;
}
for (int i = 1; i <= L; i++) {
for (int j = 1; j <= R; j++) {
for (int k = 1; k <= C; k++) {
cin >> g[i][j][k];
if (g[i][j][k] == 'S') {
start = {i,j,k};
}
else if (g[i][j][k] == 'E') {
END = { i,j,k };
}
}
}
}
int d = bfs();
if (d == -1) {
printf("Trapped!\n");
}
else {
printf("Escaped in %d minute(s).\n",d);
}
}
return 0;
}