#include #include #include #define N using namespace std; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x*=10;x+=c-'0'; c=getchar(); } return x*f; } //int head[N],last; //struct u2003{ // int nx,b; //}e[M]; //inline void build(int a,int b){ // e[++last].b=b; // e[last].nx=head[a]; // head[a]=last; //} int n; int zhan[30][2]; char s[12]; bool mp[12][12]; int cx[]={0,1},cy[]={1,0}; inline bool dfs(int c,int x,int y){ if(!mp[x][y])return 0; if(x==n&&y==n)return 1; for(int i=0;i<=1;i++){ int x1=x+cx[i],y1=y+cy[i]; if(x1>n||y1>n)continue; zhan[c+1][0]=x1; zhan[c+1][1]=y1; if(dfs(c+1,x1,y1))return 1; } return 0; } inline void clean(){ int fi=1; while(zhan[fi+1][0]){ mp[zhan[fi][0]][zhan[fi][1]]=0; fi++; } } inline void scan(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s+1); for(int j=1;j<=n;j++){ if(s[j]=='.')mp[i][j]=1; else mp[i][j]=0; } } if(dfs(1,1,1)){ clean(); if(dfs(1,1,1)) printf("2\n"); else printf("1\n"); } else printf("0\n"); } int main(){ int t; scanf("%d",&t); for(int i=1;i<=t;i++) scan(); return 0; }