#include<iostream>
#include<cstdio>
using namespace std;
int que1[10000];
int que2[10000];
int que3[10000];
int x1,x2,x,y,y1,y2,i,j,k,l,n,m,q,z,z1,z2;
int dx[6]={0,0,-1,1,0,0};
int dy[6]={1,-1,0,0,0,0};
int dz[6]={0,0,0,0,1,-1};
int num[100][100][100];
char map[100][100][100];
int main()
{
int f=0;
char a;
int e=1;
while(e==1)
{
f=0;
scanf("%d%d%d",&m,&n,&q);
if(m==0&&n==0&&q==0)
{
e=0;
break;
}
else
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<q;k++)
{
cin>>map[i][j][k];
if(map[i][j][k]=='S')
{
x1=i;
y1=j;
z1=k;
que1[1]=x1;
que2[1]=y1;
que3[1]=z1;
num[x1][y1][z1]=0;
}
if(map[i][j][k]=='E')
{
x2=i;
y2=j;
z2=k;
}
}
}
}
int head=0;
int tail=1;
while(head!=tail)
{
head++;
for(l=0;l<=5;l++)
{
x=que1[head]+dx[l];
y=que2[head]+dy[l];
z=que3[head]+dz[l];
if(x>=0&&x<m&&y>=0&&y<n&&z>=0&&z<q&&map[x][y][z]!='#')
{
tail++;
que1[tail]=x;
que2[tail]=y;
que3[tail]=z;
num[x][y][z]=num[que1[head]][que2[head]][que3[head]]+1;
if(x==x2&&y==y2&&z==z2&&map[x][y][z]=='E')
{
f=1;
cout<<"Escaped in "<<num[x][y][z]<<" minute(s)."<<endl;
head=tail+10;
break;
}
map[x][y][z]='#';
}
}
if(f==1)break;
}
if(f==0)cout<<"Trapped!"<<endl;
}
}
return 0;
}