#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<array>
#include<queue>
using namespace std;
array<array<array<char, 34>, 34>, 34>dl = {'#'};
typedef pair<int, int>mid;
typedef pair<mid, int>P;
int main() {
int l, r, c;
while (cin >> l >> r >> c) {
if (!l)
break;
int start_end[3][2];
for (int i = 1; i <= l; i++) {
for (int j = 1; j <= r; j++) {
for (int k = 1; k <= c; k++) {
cin >> dl[i][j][k];
if (dl[i][j][k] == 'S') {
start_end[0][0] = i;
start_end[1][0] = j;
start_end[2][0] = k;
//dl[i][j][k] = '#';
}
if (dl[i][j][k] == 'E') {
start_end[0][1] = i;
start_end[1][1] = j;
start_end[2][1] = k;
//dl[i][j][k] = '#';
}
}
}
}
queue<P> q;
q.push(P(mid(start_end[0][0], start_end[1][0]), start_end[2][0]));
array<array<array<int, 34>, 34>, 34>cost = { 0 };
bool fg = true;
while (!q.empty()) {
P point = q.front();
q.pop();
mid pre = point.first;
int L = pre.first;
int R = pre.second;
int C = point.second;
int costnow = cost[L][R][C];
if (L == start_end[0][1] && R == start_end[1][1] && C == start_end[2][1]) {//找到了
printf("Escaped in %d minute(s).\n", costnow);
fg = false;
break;
}
if (dl[L - 1][R][C] == '.'|| dl[L - 1][R][C] == 'E') {
dl[L - 1][R][C] = '#';
cost[L - 1][R][C]=costnow+1;
q.push(P(mid(L - 1, R), C));
}
if (dl[L + 1][R][C] == '.'|| dl[L + 1][R][C] == 'E') {
dl[L + 1][R][C] = '#';
cost[L + 1][R][C] = costnow + 1;
q.push(P(mid(L + 1, R), C));
}
if (dl[L][R + 1][C] == '.'|| dl[L][R + 1][C] == 'E') {
dl[L][R+1][C] = '#';
cost[L][R + 1][C] = costnow + 1;
q.push(P(mid(L, R + 1), C));
}
if (dl[L][R - 1][C] == '.'|| dl[L][R - 1][C] == 'E') {
dl[L][R - 1][C] = '#';
cost[L][R - 1][C] = costnow + 1;
q.push(P(mid(L, R - 1), C));
}
if (dl[L][R][C + 1] == '.'|| dl[L][R][C + 1] == 'E') {
dl[L][R][C+1] = '#';
cost[L][R][C + 1] = costnow + 1;
q.push(P(mid(L, R), C + 1));
}
if (dl[L][R][C - 1] == '.'|| dl[L][R][C - 1] == 'E') {
dl[L][R][C - 1] = '#';
cost[L][R][C - 1] = costnow + 1;
q.push(P(mid(L, R), C - 1));
}
}
if (fg) {
cout << "Trapped!" << endl;
}
}
return 0;
}