#include <stdio.h> #include <stdlib.h> int l,r,c,i,j,k,front,rear,x1,y1,z1; int map[35][35][35],len[3000]; struct que { int x,y,z; }que[3000]; int xx[]={0,0,1,-1,0,0}; int yy[]={0,1,0,0,-1,0}; int zz[]={1,0,0,0,0,-1}; int bfs() { front=0;rear=0;len[0]=0; while(front<=rear) { // printf("2"); for(i=0;i<6;i++) { x1=que[front].x+xx[i]; y1=que[front].y+yy[i]; z1=que[front].z+zz[i]; if(x1>0&&y1>0&&z1>0&&x1<=c&&y1<=r&&z1<=l&&(map[z1][y1][x1]==‘.‘||map[z1][y1][x1]==‘E‘)) { que[++rear].x=x1; que[rear].y=y1; que[rear].z=z1; len[rear]=len[front]+1; if(map[z1][y1][x1]==‘E‘) return len[rear]; else map[z1][y1][x1]=‘#‘; } } front++; } return 0; } int main() { int key; while(scanf("%d %d %d",&l,&r,&c)==3) { if(!l&&!r&&!c)return 0; for(i=1;i<=l;i++) for(j=1;j<=r;j++) for(k=1;k<=c;k++) { while(1) { scanf("%c",&map[i][j][k]); if(map[i][j][k]==‘.‘||map[i][j][k]==‘S‘||map[i][j][k]==‘E‘||map[i][j][k]==‘#‘) { if(map[i][j][k]==‘S‘) { que[0].z=i; que[0].y=j; que[0].x=i; } break; } } } key=bfs(); if(key) printf("Escaped in %d minute(s).\n",key); else printf("Trapped!\n"); // for(i=1;i<=l;i++) // for(j=1;j<=r;j++) // for(k=1;k<=c;k++) // printf(" %c",map[i][j][k]); } return 0; }