#include using namespace std; int n; int f[13][13]; char m[13][13]; void calc(){ for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ if (m[i][j]=='.') f[i][j]+=f[i-1][j]+f[i][j-1]; else f[i][j]=0; } } } int main(){ int tt;scanf("%d",&tt); for (;tt--;){ scanf("%d",&n); for (int i=1;i<=n;i++){ for (int j=1;j<=n;j++){ char ch=getchar(); while (!(ch=='#'||ch=='.')) ch=getchar(); m[i][j]=ch; } } if (m[1][1]=='#'||m[n][n]=='#'){ puts("0"); continue; } memset(f,0,sizeof(f)); f[2][1]=1; calc(); int ac=f[n][n-1],ad=f[n-1][n]; memset(f,0,sizeof(f)); f[1][2]=1; calc(); int bc=f[n][n-1],bd=f[n-1][n]; if (ac*bd-ad*bc>0){ puts("2"); continue; } memset(f,0,sizeof(f)); f[1][1]=1; calc(); if (f[n][n]>0) puts("1"); else puts("0"); } }