#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N = 105;
int l, r, c, sx, sy, sz, res;
char ch[N][N][N];
int st[N][N][N];
int x[6] = {1,-1,0,0,0,0}, y[6] = {0,0,0,0,-1,1}, z[6] = {0,0,1,-1,0,0};
struct node{
int x, y, z, step;
};
int bfs(){
queue<node> q;
q.push({sx, sy, sz, 0});
st[sx][sy][sz] = 1;
while(!q.empty()){
node now = q.front();
q.pop();
if(ch[now.x][now.y][now.z] == 'E') return now.step;
for(int i = 0; i < 6; i++){
int nx = now.x + x[i], ny = now.y + y[i], nz = now.z + z[i], ns = now.step + 1;
if(nx < 0 || nx >= l || ny < 0 || ny >= r || nz < 0 || nz >= c || st[nx][ny][nz] || ch[nx][ny][nz] == '#') continue;
st[nx][ny][nz] = 1;
q.push({nx, ny, nz, ns});
}
}
return -1;
}
int main(){
while(cin >> l >> r >> c){
if(l == 0 && r == 0 && c == 0) break;
memset(st, 0, sizeof(st));
for(int i = 0; i < l; i++){
for(int j = 0; j < r; j++){
scanf("%s", &ch[i][j]);
for(int k = 0; k < c; k++){
char c = ch[i][j][k];
if(c == 'S'){
sx = i;
sy = j;
sz = k;
}
}
}
}
res = bfs();
if(res == -1) cout << "Trapped!" << endl;
else cout << "Escaped in " << res << " minute(s)." << endl;
}
return 0;
}