1 #include<stdio.h>
2 #include<iostream>
3 #include<string.h>
4 #include<math.h>
5 #include<algorithm>
6 #include<vector>
7 #include<string>
8 #include<queue>
9 #include<map>
10 #include<stack>
11 #include<set>
12 #define ll long long
13 #define maxn 100010
14 #define PI acos(-1.0) //圆周率
15 const ll INF = 1e18;
16 using namespace std;
17 struct node
18 {
19 int x,y,z;
20 int step;
21 }fi;
22 queue <node> q;
23 int l,r,c;
24 string maze[35][35];
25 int vis[35][35][35];
26 int ff[6][3]={1,0,0,
27 -1,0,0,
28 0,1,0,
29 0,-1,0,
30 0,0,1,
31 0,0,-1};
32 bool judge(int q,int w,int e)
33 {
34 if(q<l&&q>=0&&w<r&&w>=0&&e<c&&e>=0) return true;
35 else return false;
36 }
37 int bfs()
38 {
39 q.push(fi);
40 vis[fi.x][fi.y][fi.z]=1;
41 while(!q.empty())
42 {
43 node temp=q.front();
44 q.pop();
45
46 if(maze[temp.x][temp.y][temp.z]=='E') return temp.step;
47
48 for(int i=0;i<6;i++)
49 {
50 fi.x=temp.x+ff[i][0];
51 fi.y=temp.y+ff[i][1];
52 fi.z=temp.z+ff[i][2];
53 fi.step=temp.step+1;
54
55 if(judge(fi.x,fi.y,fi.z)&&maze[fi.x][fi.y][fi.z]!='#'&&!vis[fi.x][fi.y][fi.z])
56 {
57 q.push(fi);
58 vis[fi.x][fi.y][fi.z]=1;
59 }
60 }
61 }
62
63 return -1;
64 }
65 int main()
66 {
67 while(scanf("%d %d %d",&l,&r,&c)!=EOF&&l&&r&&c)
68 {
69 memset(vis,0,sizeof(vis));
70
71 while(!q.empty()) q.pop();
72
73 for(int i=0;i<l;i++)
74 {
75 for(int j=0;j<r;j++)
76 {
77 cin>>maze[i][j];
78 for(int k=0;k<c;k++)
79 {
80 if(maze[i][j][k]=='S')
81 {
82 fi.x=i;
83 fi.y=j;
84 fi.z=k;
85 fi.step=0;
86 }
87 }
88 }
89 }
90
91 int ans=bfs();
92 if(ans==-1) printf("Trapped!
");
93 else printf("Escaped in %d minute(s).
",ans);
94 }
95
96 return 0;
97 }