/*
Coder: Shawn_Xue
Date: 2015.4.4
Result: AC
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstdlib>
using namespace std;
const int MAX = 11;
const int INF = INT_MAX-3;
/* define direction :forward, back, left, right, up, down */
const int dirx[6] = { 1,-1, 0, 0, 0, 0};
const int diry[6] = { 0, 0, 1,-1, 0, 0};
const int dirz[6] = { 0, 0, 0, 0, 1,-1};
char MYmap[MAX][MAX][MAX];
int dist[MAX][MAX][MAX];
int sx, sy, sz, dx, dy, dz;
int minx, n;
void dfs(int x, int y, int z, int cnt)
{
// 越界
if(x<0 || y<0 || z<0 || x>= n || y>=n || z>=n) return;
// 出现障碍
if(MYmap[z][x][y] == 'X') return;
// 到达
if(x==dx && y==dy && z==dz)
{
if(cnt < minx) minx = cnt;
return;
}
// 走过
if(dist[z][x][y] <= cnt)
return;
// 没走过,赋值做标记
else dist[z][x][y] = cnt;
int i, tx, ty, tz;
// 沿六个方向分别走
for(i = 0; i < 6; i ++)
{
tx = x + dirx[i];
ty = y + diry[i];
tz = z + dirz[i];
dfs(tx, ty, tz, cnt+1);
}
}
int main()
{
char str[10];
int i, j, k, cnt;
while(scanf("%s %d%*c", str, &n) != EOF)
{
for(i = 0; i < n; ++i )
{
for(k = 0; k < n; ++k)
{
for(j = 0; j < n; ++j)
{
MYmap[i][k][j] = getchar();
dist[i][k][j] = INF;
}
getchar();
}
}
cin >> sy >> sx >> sz;//起始位置
cin >> dy >> dx >> dz;//目的位置
cin >> str;
cnt = 0;
minx = INT_MAX;
dfs(sx, sy, sz, cnt);
if(minx == INT_MAX)
cout << "NO ROUTE" << endl;
else
cout << n <<" " << minx << endl;
}
return 0;
}