#include<bits/stdc++.h>
using namespace std;
char a[31][31][31];
int b,x,y,z,s=0,ans=100000;
int n,m;
void dfs(int z1,int x1,int y1,int s){
if(a[z1][x1][y1]=='#'||z1>b||z1<1||x1>n||x1<1||y1>m||y1<1) return;
if(a[z1][x1][y1]=='E'){
ans=min(ans,s);
return;
}
a[z1][x1][y1]='#';
dfs(z1+1,x1,y1,s+1);
dfs(z1-1,x1,y1,s+1);
dfs(z1,x1+1,y1,s+1);
dfs(z1,x1-1,y1,s+1);
dfs(z1,x1,y1+1,s+1);
dfs(z1,x1,y1-1,s+1);
}
int main(){
cin>>b>>n>>m;
for(int i = 1;i <= b;i++)
for(int j = 1;j <= n;j++)
for(int w = 1;w <= m;w++){
cin>>a[i][j][w];
if(a[i][j][w]=='S'){
z=i;x=j;y=w;
}
}
dfs(z,x,y,s);
if(ans==100000) cout<<"Trapped!";
else cout<<"Escaped in "<<ans<<" minute(s).";
}