#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int n, sx, sy, sz, ex, ey, ez;
char mp[15][15][15];
int vis[15][15][15];
int d[6][3] = { 0,0,1,0,1,0,1,0,0,0,0,-1,0,-1,0,-1,0,0 };
struct node
{
int x, y, z, step;
};
void bfs()
{
memset(vis, 0, sizeof(vis));
queue<node>q;
node s, e;
s.x = sx;
s.y = sy;
s.z = sz;
s.step = 0;
vis[s.x][s.y][s.z] = 1;
q.push(s);
while (!q.empty())
{
e = q.front();
q.pop();
if (e.x == ex &&e.y == ey && e.z == ez)
{
printf("%d %d\n", n, e.step);
return;
}
for (int i = 0; i<6; i++)
{
s.x = e.x + d[i][0];
s.y = e.y + d[i][1];
s.z = e.z + d[i][2];
s.step = e.step + 1;
if (s.x<0 || s.x>n - 1 || s.y<0 || s.y>n - 1 || s.z<0 || s.z>n - 1 ||
vis[s.x][s.y][s.z] == 1 || mp[s.x][s.y][s.z] == 'X') continue;
vis[s.x][s.y][s.z] = 1;
q.push(s);
}
}
printf("NO ROUTE\n");
}
int main()
{
char s[10];
while (~scanf("%s", s))
{
scanf("%d", &n);
for (int i = 0; i<n; i++)
{
//getchar();
for (int j = 0; j<n; j++)
{
getchar();
for (int k = 0; k<n; k++)
{
scanf("%c", &mp[i][j][k]);
}
}
}
scanf("%d%d%d", &sz, &sy, &sx);
scanf("%d%d%d", &ez, &ey, &ex);
scanf("%s", s);
bfs();
}
return 0;
}