/*
Author: 2486
Memory: 1452 KB Time: 0 MS
Language: G++ Result: Accepted
*/
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=+5;
char maps[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
char op[10];
int n;
int a[10];
int dx[]={0,0,1,0,-1,0};
int dy[]={0,0,0,1,0,-1};
int dz[]={1,-1,0,0,0,0};
struct obje{
int x,y,z,steps;
obje(int x,int y,int z,int steps):x(x),y(y),z(z),steps(steps){}
bool operator<(const obje &a)const{
return steps>a.steps;
}
};
void bfs(){
priority_queue<obje>G;
G.push(obje(a[0],a[1],a[2],0));
while(!G.empty()){
obje e=G.top();
G.pop();
if(e.x<0||e.y<0||e.z<0||e.x>=n||e.y>=n||e.z>=n||maps[e.x][e.y][e.z]==‘X‘||vis[e.x][e.y][e.z])continue;
vis[e.x][e.y][e.z]=true;
if(e.x==a[3]&&e.y==a[4]&&e.z==a[5]){
printf("%d %d\n",n,e.steps);
return;
}
for(int i=0;i<6;i++){
int nx=e.x+dx[i];
int ny=e.y+dy[i];
int nz=e.z+dz[i];
G.push(obje(nx,ny,nz,e.steps+1));
}
}
printf("NO ROUTE\n");
}
int main(){
#ifndef ONLINE_JUDGE//本博客有介绍其用处
freopen("D://imput.txt","r",stdin);
#endif // ONLINE_JUDGE
while(~scanf("%s%d",op,&n)){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
scanf("%s",maps[i][j]);
}
}
for(int i=5;i>=0;i--){
scanf("%d",&a[i]);
}
scanf("%s",op);
bfs();
}
return 0;
}