#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int N = 1e2 + 5;
int l, r, c;
char arr[N][N][N];
bool st[N][N][N];
int dz[] = {1, -1};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
struct Node{
int z;
int x;
int y;
int step;
}start;
bool valid(int z, int x, int y)
{
return z >= 0 && z < l && x >= 0 && x < r && y >= 0 && y < c;
}
int bfs()
{
memset(st, false, sizeof(st));
st[start.z][start.x][start.y] = true;
queue<Node> q;
q.push(start);
while (!q.empty())
{
Node now = q.front();
q.pop();
// printf("%d %d %d %d\n", now.z, now.x, now.y, now.step);
// cout << arr[now.z][now.x][now.y] << endl;
for (int i = 0; i < 4; ++i)
{
int nz = now.z, nx = now.x + dx[i], ny = now.y + dy[i];
if (valid(nz, nx, ny) && arr[nz][nx][ny] != '#' && !st[nz][nx][ny])
{
if (arr[nz][nx][ny] == 'E')
return now.step+1;
st[nz][nx][ny] = true;
q.push({nz, nx, ny, now.step+1});
}
}
for (int i = 0; i < 2; ++i)
{
int nz = now.z + dz[i], nx = now.x, ny = now.y;
if (valid(nz, nx, ny) && arr[nz][nx][ny] != '#' && !st[nz][nx][ny])
{
if (arr[nz][nx][ny] == 'E')
return now.step+1;
st[nz][nx][ny] = true;
q.push({nz, nx, ny, now.step+1});
}
}
}
return -1;
}
int main()
{
while (scanf("%d %d %d", &l, &r, &c) && l+r+c)
{
for (int i = 0; i < l; ++i)
{
for (int j = 0; j < r; ++j)
{
for (int k = 0; k < c; ++k)
{
cin >> arr[i][j][k];
if (arr[i][j][k] == 'S')
start = {i, j, k, 0};
}
}
}
int res = bfs();
if (res == -1)
puts("Trapped!");
else
printf("Escaped in %d minute(s).\n", res);
}
return 0;
}