#include<bits/stdc++.h>
#include <clocale>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--)solve();
return 0;
}
const int nn = 111;
struct lc
{
int x, y, z;
};
char g[nn][nn][nn];
int l, r, c;
lc s;
queue<pair<lc, int>> q;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }, dz[3] = { -1,0,1 };
void solve()
{
while (cin >> l >> r >> c)
{
if (!l && !r && !c)return;
for (int i = 1; i <= l; i++)
for (int j = 1; j <= r; j++)
for (int k = 1; k <= c; k++)
cin >> g[i][j][k];
for (int i = 1; i <= l; i++)
for (int j = 1; j <= r; j++)
for (int k = 1; k <= c; k++)
if (g[i][j][k] == 'S')
s.x = j, s.y = k, s.z = i, g[i][j][k] = '#';
queue<pair<lc, int>>().swap(q);
q.push({ s,0 });
while (!q.empty())
{
lc k = q.front().first;
int cnt = q.front().second;
q.pop();
int x = k.x, y = k.y, z = k.z;
for (int j = 0; j < 4; j++)
{
int xx = x + dx[j], yy = y + dy[j], zz = z + dz[1];
if (xx<1 || xx>r || yy<1 || yy>c || zz<1 || zz>l || g[zz][xx][yy] == '#')continue;
else
{
if (g[zz][xx][yy] == 'E')
{
cout << "Escaped in " << cnt + 1 << " minute(s)." << endl;
goto loop;
}
else
{
q.push({ {xx,yy,zz},cnt + 1 });
g[zz][xx][yy] = '#';
}
}
}
for (int i = 0; i < 3; i++)
{
if (i == 1)continue;
int zz = z + dz[i];
if (zz<1 || zz>l || g[zz][x][y] == '#')continue;
else
{
if (g[zz][x][y] == 'E')
{
cout << "Escaped in " << cnt + 1 << " minute(s)." << endl;
goto loop;
}
else
{
q.push({ {x,y,zz},cnt + 1 });
g[zz][x][y] = '#';
}
}
}
}
cout << "Trapped!" << endl;
loop:;
}
}