python dfs
from typing import List
class Solution:
def main(self, sx:int, sy:int, ex:int, ey:int, n: int, G:List[List[int]]):
dirs=[[-1, 0], [0, 1], [1, 0], [0, -1]]
vis = [[False for _ in range(n)] for _ in range(n)]
def dfs(x, y):
if G[x][y]=='#': return False
if x==ex and y==ey: return True
vis[x][y]=True
for d in dirs:
nx, ny = x+d[0], y+d[1]
if 0<=nx and nx<n and 0<=ny and ny<n and not vis[nx][ny] and G[nx][ny]=='.':
if dfs(nx, ny): return True
return False
if dfs(sx, sy): print("YES")
else: print("NO")
if __name__ == '__main__':
T=int(input())
sol=Solution()
for _ in range(T):
n=int(input())
G=[[] for _ in range(n)]
for i in range(n):
G[i]=list(map(str, input()))
sx, sy, ex, ey = map(int, input().split())
sol.main(sx, sy, ex, ey, n, G)
c++ dfs
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int n, T;
char G[N][N];
bool vis[N][N];
const int dirs[4][2]={{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int xa, ya, xb, yb;
bool dfs(int x, int y){
if(G[x][y]=='#') return false;
if(x==xb && y==yb) return true;
vis[x][y]=true;
for(int i=0; i<4; ++i){
int nx=x+dirs[i][0];
int ny=y+dirs[i][1];
if(0<=nx && nx<n && 0<=ny &&ny<n && !vis[nx][ny] && G[nx][ny]=='.'){
if(dfs(nx, ny)) return true;
}
}
return false;
}
int main(){
cin>>T;
while(T--){
cin>>n;
for(int i=0; i<n; ++i) cin>>G[i];
memset(vis, 0x00, sizeof vis);
cin>>xa>>ya>>xb>>yb;
if(dfs(xa, ya)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}