#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
char s[110][110][110];
bool t[110][110][110];
int dis[110][110][110];
int dx[6] = {-1, 0, 1, 0, 0, 0}, dy[6] = {0, 1, 0, -1, 0, 0},dz[6] = {0, 0, 0, 0, -1, 1};
int l, n, m;
struct cod{
int z;
int x;
int y;
};
cod st,ed;
int ans = 0;
int bfs (cod st)
{
memset(dis, 0, sizeof dis);
queue<cod>q;
t[st.z][st.x][st.y] = true;
q.push(st);
while(q.size())
{
cod f = q.front();
q.pop();
for(int i = 0;i < 6; i ++)
{
int z = dz[i] + f.z, x = dx[i] + f.x, y = dy[i] + f.y;
if(x < 1 || x > n || y < 1 || y > m || z < 1 ||z > l)continue;
else if(s[z][x][y]=='#')continue;
else if(t[z][x][y])continue;
else {
t[z][x][y] = true;
dis[z][x][y] = dis[f.z][f.x][f.y] + 1;
if(s[z][x][y] == 'E')return dis[z][x][y];
cod g = {z, x, y};
q.push(g);
}
}
}
return 0;
}
int main()
{
while(cin >>l >>n >>m, l || n || m)
{
ans = 0;
for(int i = 1;i <= l; i ++)
{
for(int j = 1;j <= n; j ++)
{
for(int k = 1;k <= m; k ++)
{
cin >>s[i][j][k];
if(s[i][j][k] == 'S')st = {i, j, k};
}
}
}
int ans = bfs(st);
memset(t, 0, sizeof t);
if(ans!=0)printf("Escaped in %d minute(s).\n" ,ans);
else{
printf("Trapped!\n");
}
}
}