/*
很水的bfs,一开始bfs不会,用dfs错了好多次,应该是算法有问题吧,我觉得这个题目用dfs
应该可以的
*/
#include<iostream>//2389356 2010-04-27 11:23:31 Accepted 1240 0MS 308K 1495 B C++ 悔惜晟
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
char map[12][12][12];
bool hash[12][12][12];
bool flag;
int dir[6][3] = {{0, 0, 1}, {0, 1, 0}, {0, 0, -1}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0} };
int a, b, c;
int d, e, f;
int t;
int n;
struct node
{
int x;
int y;
int z;
int num;
};
queue<node> q;
int bfs(int si, int sj, int sk)
{
node N, P;
N.x = si;
N.y = sj;
N.z = sk;
N.num = 0;
int i;
q.push(N);
hash[si][sj][sk] = false;
while(!q.empty())
{
N = q.front();
if(N.x == f && N.y == e && N.z == d && N.num == t)
{
flag = true;
cout<<n<<" "<<N.num<<endl;
break;
}
if(N.num > t)
{
break;
}
q.pop();
for(i = 0; i < 6; i++)
{
P.x = N.x + dir[i][0];
P.y = N.y + dir[i][1];
P.z = N.z + dir[i][2];
if(P.x >= 0 && P.x < n && P.y >= 0 && P.y < n && P.z >= 0 && P.z < n && hash[P.x][P.y][P.z] && map[P.x][P.y][P.z] == 'O')
{
P.num = N.num + 1;
q.push(P);
hash[P.x][P.y][P.z] = false;
}
}
}
return 1;
}
int main()
{
char str[12];
int i, j ,k;
while(cin>>str>>n)
{
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
for(k = 0; k < n; k++)
cin>>map[i][j][k];
cin>>a>>b>>c;
cin>>d>>e>>f;
cin>>str;
t = (int)(fabs(1.0*a - d) + fabs(1.0*b - e) + fabs(1.0*c - f)); //省赛的时候这样的CE过
flag = false;
memset(hash, true, sizeof(hash));//一开始这里标记错了,以后应该规定标记的,不然写写就会错了
bfs(c, b ,a);
if(!flag)
cout<<"NO ROUTE"<<endl;
}
}