#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
const int N = 110;
typedef pair<int, pair<int, int>> PIII;
int l, r, c;
int startZ, startX, startY;
int endZ, endX, endY;
char g[N][N][N];
int d[N][N][N];
void bfs(int z, int x, int y)
{
queue<PIII> q;
q.push({z, {x, y}});
memset(d, -1, sizeof d);
d[z][x][y] = 0;
int dx[6] = {0, 0, -1, 1, 0, 0};
int dy[6] = {1, -1, 0, 0, 0, 0};
int dz[6] = {0, 0, 0, 0, 1, -1};
while (q.size())
{
auto t = q.front();
q.pop();
for (int i = 0; i < 6; i ++ )
{
int x = t.second.first + dx[i], y = t.second.second + dy[i], z = t.first + dz[i];
if (x >= 0 && x < r && y >= 0 && y < c && z >= 0 && z < l && d[z][x][y] == -1 && (g[z][x][y] == '.' || g[z][x][y] == 'E'))
{
d[z][x][y] = d[t.first][t.second.first][t.second.second] + 1;
q.push({z, {x, y}});
}
}
}
if (d[endZ][endX][endY] == -1) cout << "Trapped!" << endl;
else cout << "Escaped in " << d[endZ][endX][endY] << " minute(s)." << endl;
}
int main()
{
while (true)
{
cin >> l >> r >> c;
if (l == 0 && r == 0 && c == 0) break;
for (int i = 0; i < l; i ++ )
for (int j = 0; j < r; j ++ )
for (int k = 0; k < c; k ++ )
{
cin >> g[i][j][k];
if (g[i][j][k] == 'E') endZ = i, endX = j, endY = k;
if (g[i][j][k] == 'S') startZ = i, startX = j, startY = k;
}
bfs(startZ, startX, startY);
}
return 0;
}