#include<iostream>
#include<queue>
using namespace std;
int MAP[6][3]={{1,0,0},{0,-1,0},{0,1,0},{-1,0,0},{0,0,1},{0,0,-1}};
char a[30][30][30];
int x,y,z;
typedef struct
{
int z;
int y;
int x;
int moves;
}NodeStru;
NodeStru temp,start,end;
int bfs(queue<NodeStru> knight,int n,int hen,int lie)
{
int i;
while(!knight.empty())
{
temp=knight.front();
knight.pop();
if(temp.x==end.x && temp.y==end.y && temp.z==end.z)
return 1;
for(i=0;i<6;i++)
{
z=temp.z+MAP[i][2];
y=temp.y+MAP[i][1];
x=temp.x+MAP[i][0];
if(x>=0 && x<lie && y>=0 && y<hen && z>=0 && z<n && !(a[z][y][x]=='#'))
{
start.x=x;
start.y=y;
start.z=z;
start.moves=temp.moves+1;
knight.push(start);
a[z][y][x]='#';
}
}
}
return 0;
}
int main()
{
int n,hen,lie,i,j,k;
while((cin>>n>>hen>>lie) && !(n==0&&lie==0&&hen==0))
{
queue<NodeStru> knight;
for(k=0;k<n;k++)
for(i=0;i<hen;i++)
for(j=0;j<lie;j++)
{
cin>>a[k][i][j];
if(a[k][i][j]=='S')
{
start.z=k;
start.y=i;
start.x=j;
a[k][i][j]='#';
}
if(a[k][i][j]=='E')
{
end.z=k;
end.y=i;
end.x=j;
}
}
start.moves=0;
knight.push(start);
if(bfs(knight,n,hen,lie))
cout<<"Escaped in "<<temp.moves<<" minute(s)."<<endl;
else
cout<<"Trapped!"<<endl;
}
return 0;
}