#include #include #include #include #include #include #define ll long long using namespace std; const int N=11; int T,n,s[N*2],t[N*2]; bool a[N][N]; char ch[N+2]; bool dfs1(int i,int j) { if(!a[i][j])return 0; s[++s[0]]=(i-1)*n+j; if(i==n&&j==n)return 1; if(dfs1(i,j+1))return 1; if(dfs1(i+1,j))return 1; --s[0]; return 0; } bool dfs2(int i,int j) { if(!a[i][j])return 0; t[++t[0]]=(i-1)*n+j; if(i==n&&j==n)return 1; if(dfs2(i+1,j))return 1; if(dfs2(i,j+1))return 1; --t[0]; return 0; } int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",ch+1); for(int j=1;j<=n;j++) if(ch[j]=='#')a[i][j]=0; else a[i][j]=1; } for(int i=1;i<=n+1;i++) a[i][n+1]=a[n+1][i]=0; s[0]=t[0]=0; if(!dfs1(1,1)){printf("0\n");continue;} dfs2(1,1); int flg=2; for(int i=2;i