//* Problem  : D - Dungeon Master
//* Contest  : UzhNU Local
//* Origin   : Ulm-1997
//* Type     : Solution
//* Date     : 2008.02.04
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0
//* Algoritm : BFS

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <queue>

struct point{
	int x, y, z;
};

char a[32][32][32];

int vis[32][32][32];

int n, m, p, res;

int dx[] = { 1, -1,  0,  0,  0,  0};
int dy[] = { 0,  0,  1, -1,  0,  0};
int dz[] = { 0,  0,  0,  0,  1, -1};

void solve()
{
	memset(vis, 0, sizeof(vis));
	point pt; std::queue <point> q;
	res = -1;
	int i, j, k, x, y, z, d, xt, yt, zt;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
			for (k = 1; k <= p; k++)
				if (a[i][j][k] == 'S')
				{
					pt.x = i; pt.y = j; pt.z = k; q.push(pt); vis[i][j][k] = 1;
				}
	while (!q.empty())
	{
		pt = q.front(); q.pop();
		x = pt.x; y = pt.y; z = pt.z; d = vis[x][y][z];
		for (int i = 0; i < 6; i++)
		{
			xt = x + dx[i]; yt = y + dy[i]; zt = z + dz[i];
			if (a[xt][yt][zt] == '.' && !vis[xt][yt][zt])
			{
				vis[xt][yt][zt] = d + 1; pt.x = xt; pt.y = yt; pt.z = zt;
				q.push(pt);
			}
			if (a[xt][yt][zt] == 'E') {res = d; return;}
		}
		
	}

}

int main()
{
	while (scanf("%d%d%d", &n, &m, &p) == 3 && n)
	{
		memset(a, 0, sizeof(a));
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				scanf("%s", &a[i][j][1]);
		solve();
		if (res < 0) printf("Trapped!\n");
			else printf("Escaped in %d minute(s).\n", res);
	}
	return 0;
}