#include<bits/stdc++.h>
using namespace std;
struct node
{
int x;
int y;
int z;
int d;
};
int x, y, z, sx, sy, sz;
char a[35][35][35];
bool vis[35][35][35];
int dir[6][3] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
inline int bfs()
{
queue<node> q;
q.push((node){sx, sy, sz, 0}), vis[sx][sy][sz] = 1;
while (!q.empty())
{
node now = q.front();
q.pop();
if (a[now.x][now.y][now.z] == 'E')
return now.d;
for (int i = 0, tx, ty, tz; i < 6; i++)
{
tx = now.x + dir[i][0], ty = now.y + dir[i][1], tz = now.z + dir[i][2];
if (tx < 1 || tx > x || ty < 1 || ty > y || tz < 1 || tz > z || vis[tx][ty][tz] || a[tx][ty][tz] == '#')
continue;
q.push((node){tx, ty, tz, now.d + 1}), vis[tx][ty][tz] = 1;
}
}
return -1;
}
inline bool solve()
{
cin >> x >> y >> z;
if (x == 0 && y == 0 && z == 0)
return 0;
for (int i = 1; i <= x; i++)
{
for (int j = 1; j <= y; j++)
{
for (int k = 1; k <= z; k++)
{
cin >> a[i][j][k];
if (a[i][j][k] == 'S')
sx == i, sy = j, sz = k;
}
}
}
memset(vis, 0, sizeof(vis));
int ans = bfs() - 1;
if (ans < 0)
cout << "Trapped!\n";
else
cout << "Escaped in " << ans << " minute(s).\n";
return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
while (solve());
return 0;
}