#include "iostream"
#include "queue"
#include "cstdio"
using namespace std;
typedef struct {
int x, y, z, t;
} PII;
const int N = 100;
char v[N][N][N];
int l, r, c;
struct {
int x, y, z;
} S, E;
int dx[] = {1, -1, 0, 0, 0,0};
int dy[] = {0, 0, 1, -1, 0, 0};
int dz[] = {0, 0, 0, 0, 1, -1};
int main()
{
while (cin >> l >> r >> c)
{
queue<PII>q;
bool vis[N][N][N];
if(l==0 && r == 0 && c == 0) break;
for(int t=1; t<=l; t++)
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
{
cin >> v[i][j][t];
if (v[i][j][t] == 'S')
S.z = t, S.x = i, S.y = j;
if (v[i][j][t] == 'E')
E.z = t, E.x = i, E.y = j;
}
q.push({S.x, S.y, S.z, 0});
vis[S.x][S.y][S.z] = true;
bool tag = false;
while (!q.empty())
{
int x = q.front().x, y = q.front().y, z = q.front().z, t = q.front().t;
if(v[x][y][z] == 'E')
{
tag = true;
printf("Escaped in %d minute(s).\n", t);
break;
}
q.pop();
for(int i=0; i<=5; i++)
{
int ux = x + dx[i], uy = y + dy[i], ut = t, uz = z + dz[i];
if (ux >= 1 && ux <= r && uy >= 1 && uy <= c && uz >= 1 && uz <= l && !vis[ux][uy][uz] && v[ux][uy][uz] != '#')
q.push({ux, uy, uz, ut + 1});
}
}
if(!tag)
puts("Trapped!");
}
return 0;
}