1 #include<iostream>
2 #include<cstring>
3 using namespace std;
4 int map[20][20];
5 int d[5]={0,1,0,-1,0};
6 int n,m;
7 char s;
8 void dfs(int a,int b)
9 {
10 if(a==m&&b==m)return ;
11 for(int i=0;i<4;++i)
12 {
13 int h=a+d[i];
14 int z=b+d[i+1];
15 if((h<=m)&&(h>0)&&(z>0)&&(z<=m)&&map[h][z]==0)
16 {
17 map[h][z]=1;
18 dfs(h,z);
19 }
20 }
21 }
22 int main()
23 {
24 cin>>n;
25 while(n--)
26 {
27 memset(map,0,sizeof(map));
28 cin>>m;
29 for(int i=1;i<=m;++i)
30 {
31 for(int j=1;j<=m;++j)
32 {
33 cin>>s;
34 if(s==‘#‘)map[i][j]=1;
35 }
36 }
37 map[1][1]=1;
38 dfs(1,1);
39 if(map[m][m])cout<<"YES\n";
40 else cout<<"NO\n";
41 }
42 return 0;
43 }