/*
最简单广搜多了一维而已,杭电这题代码数据实在是太弱了,估计就一组,各种错误代码都过了。有兴趣的可以去提交北大poj2225
*/
#include<iostream>
#include<stdio.h>
#include<string>
#include<cstring>
#include<queue>
#define N 22
#define max 999999
#define min(a, b) (a>b?b:a)
using namespace std;
int n, mark[N][N][N], dir[6][3] = {1,0,0, -1,0,0, 0,1,0, 0,-1,0, 0,0,1, 0,0,-1};
int s_x, s_y, s_z, e_x, e_y, e_z;
char str[N][N][N];
struct node
{
int x, y, z, step;
};
int judge(int x, int y, int z)
{
if(x>=0 && x<n && y>=0 && y<n && z>=0 &&z<n && mark[x][y][z]==0 && str[x][y][z]=='O')
return 1;
else
return 0;
}
int bfs()
{
int i, x, y, z;
node cur, next;
queue<node>q;
cur.x=s_x; cur.y=s_y; cur.z=s_z; cur.step=0;
q.push(cur);
mark[s_x][s_y][s_z] = 1;
int ans = max;
while(!q.empty())
{
cur = q.front();
q.pop();
if(cur.x==e_x && cur.y==e_y && cur.z==e_z)
{
ans = min(ans, cur.step);
}
for( i=0; i < 6; i++ )
{
next.x = x = cur.x + dir[i][0];
next.y = y = cur.y + dir[i][1];
next.z = z = cur.z + dir[i][2];
next.step = cur.step + 1;
if(judge(x, y, z))
{
mark[x][y][z] = 1;
q.push(next);
}
}
}
if(ans>=max) return -1;
else return ans;
}
int main()
{
char ch[22];
int i, j, k;
while(scanf("%s%d", ch, &n) != -1)
{
//getchar();
memset(mark, 0, sizeof(mark));
for( i=0; i < n; i++ )
for(j=0; j < n; j++ )
{
getchar();
for(k=0; k < n; k++ )
scanf("%c", &str[k][j][i]);
}
scanf("%d%d%d", &s_x, &s_y, &s_z);
scanf("%d%d%d", &e_x, &e_y, &e_z);
scanf("%s", ch);
int ans = bfs();
if(ans==-1)
printf("NO ROUTE\n");
else
printf("%d %d\n", n, ans);
}
return 0;
}