#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 110;
// 也可以考虑C++的元组
struct Point {
int l, r, c; // 记录状态
int pre;//记录转移来的位置
};
int L, R, C;
char g[N][N][N];
int dist[N][N][N];
int dl[] = {-1, 1, 0, 0, 0, 0};//-1, 1而已
int dr[] = {0, 0, -1, 1, 0, 0};
int dc[] = {0, 0, 0, 0, -1, 1};
vector<Point> que;//需要随机索引的容器来生成路径
vector<Point> path;// 路径输出
// 倒过来找路径
void dfs(Point cur) {
if(cur.pre == -1) return;
dfs(que[cur.pre]);//前一个位置
path.push_back({cur.l, cur.r, cur.c});
}
int bfs(Point st) {
que.clear();//真正的queue不支持clear
path.clear();
memset(dist, -1, sizeof dist);
int ans = -1;
que.push_back(st);
dist[st.l][st.r][st.c] = 0;
for(int i = 0; i < que.size(); i++) {
auto cur = que[i];
// printf("%d %d %d\n", cur.l, cur.r, cur.c);
if(g[cur.l][cur.r][cur.c] == 'E') {
ans = dist[cur.l][cur.r][cur.c];
dfs(cur);
break;
}
for(int j = 0; j < 6; j++) {
int tl = cur.l+dl[j], tr = cur.r+dr[j], tc = cur.c+dc[j];
if(tl < 0 || tl >= L ||
tr < 0 || tr >= R ||
tc < 0 || tc >= C ||
g[tl][tr][tc] == '#' ||
dist[tl][tr][tc] != -1)
continue;
que.push_back({tl, tr, tc, i});
dist[tl][tr][tc] = dist[cur.l][cur.r][cur.c]+1;
}
}
return ans;
}
int main() {
Point st;
while(scanf("%d%d%d", &L, &R, &C) && L) {
for (int i = 0; i < L; i ++ ) {
for (int j = 0; j < R; j ++ ) {
for (int k = 0; k < C; k ++ ) {
scanf(" %c", &g[i][j][k]);
if(g[i][j][k] == 'S') {
st = {i, j, k, -1};//-1表示前一个转移来的位置是null
}
}
}
}
int ans = bfs(st);
if(ans != -1)
{
printf("Escaped in %d minute(s).\n", ans);
// puts("路径如下");
// for(auto i : path) {
// printf("%d %d %d\n", i.l, i.r, i.c);
// }
}
else puts("Trapped!");
}
return 0;
}