#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int n,k;
bool st[N][N];
char g[N][N];
int d[N][N];
int ha,la,hb,lb;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
pair<int,int> q[N];
int main()
{
cin>>k;
while(k--)
{
cin>>n;
for(int i = 0;i<n;i++)
{
for(int j = 0;j<n;j++)
{
cin>>g[i][j];
}
}
cin>>ha>>la>>hb>>lb;
if(ha==hb&&la==lb) puts("YES");
else if(g[ha][la]=='#'||g[hb][lb]=='#') puts("NO");
else
{
int hh = 0,tt = 0;
memset(d,-1,sizeof(d));
d[ha][la]=0;
q[0]={ha,la};
while(hh<=tt)
{
auto t = q[hh++];
for(int i = 0;i<4;i++)
{
int x = t.first+dx[i],y = t.second+dy[i];
if(x>=0&&x<n&&y>=0&&y<n&&g[x][y]=='.'&&d[x][y]==-1)
{
d[x][y]=d[t.first][t.second]+1;
q[++tt]={x,y};
}
}
}
if(d[hb][lb]>0) puts("YES");
else puts("NO");
}
}
}
卡的数据
100
10
.#.#.#....
#..####.#.
...#.#..#.
.#..#..#..
##........
...#......
....##.#.#
##......#.
#.....###.
##..#..#..
2 9 3 0
10
#.#..#....
##..#..##.
#...##....
......###.
.##..##...
......##..
..##.#.#.#
....##....
...#...##.
##..#.##..
1 9 9 9
10
##.##.####
.#.#.#...#
#...#.#...
....#.....
.#...#...#
##.....#.#
#...#....#
.#..#....#
#...#...#.
.......#..
6 7 9 1
10
#..#......
.#...##..#
.#........
#..#...#..
....####..
..#...#..#
#.........
#.....#.#.
.#....###.
.###..#...
0 6 2 7
10
......#.#.
#....#....
.#..#.....
...#......
.#..#..##.
..#...##..
.#...#..#.
..#.#..#..
.##.#.#.#.
..........
7 3 3 8
10
...#....##
..........
#.#...#...
#.#......#
.....#....
#.......#.
#####..#..
....#..#..
.......#.#
#.##......
4 8 1 7
10
#..#...##.
.##...#.#.
...##.###.
...#..##..
##..#.....
.........#
##.#...###
###.....#.
#.#..#.#.#
#....#....
4 2 9 5
10
##.......#
..#..#..##
....###...
##.#.....#
....#..#..
.#.#.###..
...##...#.
.#######.#
..#....##.
...#.##.##
8 6 8 5
10
..###.###.
.....#..#.
#....#..#.
.#..##.#..
..........
.###.#....
.....#.##.
.....#....
.#...##...
.......#.#
7 2 6 9
10
.......#..
.#..#..#..
...#..#..#
..##.###.#
#.#..#....
##.#..#...
.#........
..#.#.....
...#..#.#.
#...##..#.
7 9 9 3
10
.........#
.....#...#
#..#..#.##
...#.....#
...#....##
.#..#.....
......####
.##.#..#..
..#..#....
....#####.
8 5 2 8
10
###.....#.
#..##..#..
.........#
.#...###..
...#.#.#.#
....#.#...
..#...##..
.##......#
#..#..##.#
.#.......#
5 2 6 0
10
........#.
##.#....#.
.#....#...
..##...#..
....#..#..
#.....##.#
...#......
..##.#....
..##.##...
#.....##..
2 8 1 8
10
......#.#.
##...#.#..
##..#.#...
...##.....
...##.....
#.##.....#
...#.##...
.####.##.#
##....#...
##.##.#...
4 1 4 8
10
.#......#.
#.##.#..##
....##..#.
##.#.#...#
#..#.#....
.#..#.....
......##..
.#........
#....#.#.#
.##....###
0 8 4 7
10
#.#.###.#.
...#.##...
......###.
......##..
...##.....
......##.#
....#...##
......#.#.
##..#.....
#........#
3 6 3 0
10
..#.....#.
....#.#.#.
.##....##.
##.#.##...
....#..#.....