# 最少步数

1,1,1,1,1,1,1,1,1
1,0,0,1,0,0,1,0,1
1,0,0,1,1,0,0,0,1
1,0,1,0,1,1,0,1,1
1,0,0,0,0,1,0,0,1
1,1,0,1,0,1,0,0,1
1,1,0,1,0,1,0,0,1
1,1,0,1,0,0,0,0,1
1,1,1,1,1,1,1,1,1

0表示道路，1表示墙。

（注：一步是指从一坐标点走到其上下左右相邻坐标点，如：从（3，1）到（4,1）。）

2
3 1  5 7
3 1  6 7

12
11


#include <bits/stdc++.h>
using namespace std;
int mmin;
int we[9][9]={
1,1,1,1,1,1,1,1,1,
1,0,0,1,0,0,1,0,1,
1,0,0,1,1,0,0,0,1,
1,0,1,0,1,1,0,1,1,
1,0,0,0,0,1,0,0,1,
1,1,0,1,0,1,0,0,1,
1,1,0,1,0,1,0,0,1,
1,1,0,1,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,
};
int zz[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int aa[9][9];
void bfs(int a,int b,int s,int za,int zb){
if(a==za && b==zb){
if(mmin>s)
mmin=s;
return ;
}
for(int i=0;i<4;i++){
int xx=a+zz[i][0];
int yy=b+zz[i][1];
if(xx>=0 && xx<9 && yy>=0 && yy<9 && we[xx][yy]!=1 && aa[xx][yy]!=1){
aa[xx][yy]=1;
bfs(xx,yy,s+1,za,zb);
aa[xx][yy]=0;
}
}
return ;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
mmin=999999;
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
memset(aa,0,sizeof(aa));
aa[x1][y1]=1;
bfs(x1,y1,0,x2,y2);
printf("%d\n",mmin);
}
}

#include <bits/stdc++.h>
using namespace std;
int we[9][9]={
1,1,1,1,1,1,1,1,1,
1,0,0,1,0,0,1,0,1,
1,0,0,1,1,0,0,0,1,
1,0,1,0,1,1,0,1,1,
1,0,0,0,0,1,0,0,1,
1,1,0,1,0,1,0,0,1,
1,1,0,1,0,1,0,0,1,
1,1,0,1,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,
};
struct haha{
int x,y,w;
};
int zz[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int aa[9][9];
int dfs(int x1,int y1,int x2,int y2){
haha ans;
ans.x=x1;
ans.y=y1;
ans.w=0;
aa[x1][y1]=1;
queue<haha>q;
q.push(ans);
while(!q.empty()){
haha gg=q.front();
q.pop();
if(gg.x==x2 && gg.y==y2)
return gg.w;
for(int i=0;i<4;i++){
haha jiu;
int xx=gg.x+zz[i][0];
int yy=gg.y+zz[i][1];
if(xx>=0 && xx<9 && yy>=0 && yy<9 && we[xx][yy]!=1 && aa[xx][yy]!=1){
aa[xx][yy]=1;
jiu.x=xx;
jiu.y=yy;
jiu.w=gg.w+1;
q.push(jiu);
}
}
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int x1,y1,x2,y2;
memset(aa,0,sizeof(aa));
scanf("%d %d  %d %d",&x1,&y1,&x2,&y2);
printf("%d\n",dfs(x1,y1,x2,y2));

}
}