#include <bits/stdc++.h>
using namespace std;
int n, m, h, sx, sy, sz, ex, ey, ez;
char c[105][105][105];
struct node
{
int x, y, z, step;
};
int dir[6][3] = {1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1};
int bfs(int x, int y, int z)
{
queue<node> q;
q.push((node){x, y, z, 0});
bool vis[105][105][105] = {};
vis[x][y][z] = true;
while (!q.empty())
{
node u = q.front();
q.pop();
if (u.x == ex && u.y == ey && u.z == ez)
return u.step;
for (int i = 0; i < 6; i++)
{
int xx = u.x + dir[i][0];
int yy = u.y + dir[i][1];
int zz = u.z + dir[i][2];
if (xx >= 0 && yy >= 0 && zz >= 0 && xx < n && yy < m && zz < h && vis[xx][yy][zz] == false && c[xx][yy][zz] != '#')
{
vis[xx][yy][zz] = true;
q.push((node){xx, yy, zz, u.step + 1});
}
}
}
return 0;
}
int main()
{
while (cin >> n >> m >> h && n != 0 && m != 0 && h != 0)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < h; k++)
{
cin >> c[i][j][k];
if (c[i][j][k] == 'S')
sx = i, sy = j, sz = k;
if (c[i][j][k] == 'E')
ex = i, ey = j, ez = k;
}
int ans = bfs(sx, sy, sz);
if (ans)
printf("Escaped in %d minute(s).\n", ans);
else
printf("Trapped!\n");
}
}