#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 110;
struct Point
{
int x, y, z;
};
int L, R, C;//高 长 宽
char g[N][N][N];
Point q[N * N * N];
int dist[N][N][N];
int dx[6] = {1, -1, 0, 0, 0, 0};
int dy[6] = {0, 0, 1, -1, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};
int bfs(Point start,Point end){
queue<Point>q;
q.push(start);
memset(dist,-1,sizeof dist);
dist[start.x][start.y][start.z]=0;
while(q.size()){
Point t=q.front();
q.pop();
for(int i=0;i<6;i++){
int a=t.x+dx[i],b=t.y+dy[i],c=t.z+dz[i];
if(a<0||a>=L||b<0||b>=R||c<0||c>=C)continue;
if(g[a][b][c]=='#'||dist[a][b][c]!=-1)continue;//为障碍或者已经更新过
dist[a][b][c]=dist[t.x][t.y][t.z]+1;
if(g[a][b][c]=='E')return dist[a][b][c];
q.push({a,b,c});
}
}
return -1;
}
int main(){
while(scanf("%d%d%d",&L,&R,&C),L||R||C){
Point start,end;
for(int l=0;l<L;l++){
for(int m=0;m<R;m++){
scanf("%s",g[l][m]);
for(int c=0;c<C;c++){
if(g[l][m][c]=='S')start={l,m,c};
else if(g[l][m][c]=='E')end={l,m,c};
}
}
}
if(bfs(start,end)==-1){
printf("Trapped!\n");
}
else
printf("Escaped in %d minute(s).\n",bfs(start,end));
}
return 0;
}