#include<bits/stdc++.h>
using namespace std;
int x,y,z,sx,sy,sz,tx,ty,tz,ans;
int a[105][105][105];
int vis[105][105][105];
int xx[]={1,-1,0,0,0,0};
int yy[]={0,0,1,-1,0,0};
int zz[]={0,0,0,0,1,-1};
struct p{
int x;
int y;
int z;
int s;
};
int main(){
in:
memset(a,0,sizeof a);
memset(vis,0,sizeof vis);
cin>>x>>y>>z;
if(x==0)return 0;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
for(int k=1;k<=z;k++){
char ch;
cin>>ch;
if(ch=='#')a[i][j][k]=1;
if(ch=='S')tx=i,ty=j,tz=k;
if(ch=='E')sx=i,sy=j,sz=k;
}
}
}
queue<p>Q;
Q.push({tx,ty,tz,0});
vis[tx][ty][tz]=1;
ans=0;
while(!Q.empty()){
ans++;
if(Q.front().x==sx&&Q.front().y==sy&&Q.front().z==sz){
printf("Escaped in %d minute(s).\n",Q.front().s);
goto in;
}
for(int i=0;i<6;i++){
int dx=Q.front().x+xx[i];
int dy=Q.front().y+yy[i];
int dz=Q.front().z+zz[i];
int ds=Q.front().s+1;
if(dx>=1&&dx<=x&&dy>=1&&dy<=y&&dz>=1&&dz<=z&&!a[dx][dy][dz]&&!vis[dx][dy][dz]){
vis[dx][dy][dz]=1;
Q.push({dx,dy,dz,ds});
}
}
Q.pop();
}
cout<<"Trapped!"<<endl;
goto in;
}