#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int oo=1000000007; const int o[2][8][2]={{{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}},{{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}}; struct node { int x,y; node():x(0),y(0){}; node(int xx,int yy):x(xx),y(yy){}; }; queueque; int n,m,k,x[2],y[2],deepth[2][2000][2000]; void bfs(int root) { for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) deepth[root][i][j]=0; deepth[root][x[root]][y[root]]=1; que.push(node(x[root],y[root])); while(!que.empty()) { node cur=que.front(); que.pop(); for(int i=0;i<8;i++) { int xx=cur.x+o[root][i][0],yy=cur.y+o[root][i][1]; if(xx>0&&xx<=n&&yy>0&&yy<=m&&!deepth[root][xx][yy]) { que.push(node(xx,yy)); deepth[root][xx][yy]=deepth[root][cur.x][cur.y]+1; } } } } int get_mintime(int x,int y) { if(y>x+1) return y; if(y==x+1) return y+2; if((x-y)%2==0) return x; return x+3; } int get_ans() { int ret=oo; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(deepth[0][i][j]&&deepth[1][i][j]) ret=min(ret,get_mintime(deepth[0][i][j],deepth[1][i][j])-1); return ret; } int main() { int t; cin>>t; for(int ca=1;ca<=t;ca++) { cout<<"Case #"<>n>>m>>k>>x[0]>>y[0]>>x[1]>>y[1]; bfs(0); bfs(1); int ans=get_ans(); if(ans>k) cout<<"OH,NO!"<