Juruo is an adventurous person. Now he is trapped in a perplexing 3D maze. Due to the air is damp crisp, he has to find a quickest way out. The 3D maze is made up of unit cubes. Some cubes are filled with snakes while others are not. Snakes!!! It will take one minute to take a unit move. He can choose to go north, south, east, west, up or down, but he cannot move diagonally. 

Is an escape possible? If yes, how long will it take? 

Input

The input contains a number of 3D mazes. Each description of maze starts with a line containing three integers L, R and C (L, R, C <= 30). 
L: The number of levels makes up the maze. 
R and C: The number of rows and columns maks up the plane of each level. 
Then there will follow L blocks of R lines, and each containing C characters. Each character describes one cube of the maze. A cube full of snakes is indicated by a '#' and empty cubes are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. The Input terminates when L = R = C = 0.

Output

Each maze generates one line of output. If it is possible to reach the exit, output a line of the form: 

Escaped in x minute(s).


where x is replaced by the shortest time it takes to escape. 
If it is not possible to escape, output the line: 

Trapped!

Sample Input

3 4 5
S....
.###.
.##..
###.#

#####
#####
##.##
##...

#####
#####
#.###
####E

1 3 3
S##
#E#
###

0 0 0

Sample Output

Escaped in 11 minute(s).
Trapped!

Hint

BFS

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Node {
    int x,y,z;
    int step;
    Node() {}
    Node(int z,int y,int x,int step) {
        this.z = z;
        this.y = y;
        this.x = x;
        this.step = step;
    }
    Node(int z,int y,int x) {
        this.z = z;
        this.y = y;
        this.x = x;
    }
}
public class Main {
    static int high,row,cloum;//高,行,列
    static int[][][] map;//0表示能走,1表示不能走
    static boolean[][][] vis;
    static Queue<Node> q;
    static Node start,end;
    static int[][] move = {{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
    static boolean check(int x,int y,int z) {
        return x >= 0 && x < cloum && y >= 0 && y < row && z >= 0 && z < high && map[z][y][x] != 1 && !vis[z][y][x];
    }
    
    static void bfs() {
        Node cur,new_cur;
        vis[start.z][start.y][start.x] = true;
        q = new LinkedList<Node>();
        q.add(start);
        while(!q.isEmpty()) {
            cur = new Node(q.peek().z,q.peek().y,q.peek().x,q.poll().step);
            if(cur.x == end.x && cur.y == end.y && cur.z == end.z) {
                System.out.println("Escaped in " + cur.step + " minute(s).");
                return;
            }
            for(int i = 0;i < 6;i++) {
                new_cur = new Node(cur.z,cur.y,cur.x,cur.step);
                new_cur.x += move[i][0];
                new_cur.y += move[i][1];
                new_cur.z += move[i][2];
                if(check(new_cur.x,new_cur.y,new_cur.z)) {
                    vis[new_cur.z][new_cur.y][new_cur.x] = true;
                    new_cur.step++;
                    q.add(new_cur);
                }
            }
        }
        System.out.println("Trapped!");
    }
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()) {
            high = cin.nextInt();
            row = cin.nextInt();
            cloum = cin.nextInt();
            vis = new boolean[high][row][cloum];
            if(high == 0)
                break;
            map = new int[high][row][cloum];
            String tmp;
            for(int z = 0;z < high;z++) {//高
                for(int y = 0;y < row;y++) {//行
                    tmp = cin.next();
                    for(int x = 0;x < cloum;x++) {//列
                        if(tmp.charAt(x) == 'S') 
                            start = new Node(z,y,x,0);
                        else if(tmp.charAt(x) == 'E') 
                            end = new Node(z,y,x);
                        else if(tmp.charAt(x) == '#')
                            map[z][y][x] = 1;
                    }
                }
            }
            bfs();
        }
    }
}