#include using namespace std; #define ll long long #define db double #define X first #define Y second #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define rep0(i,a,b) for(int i=(a);i<(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define fore(i,a) for(int i=0;i>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r; }*/ int main() { int T=rd(); while(T--) { int n=rd(); int m=0,a[11][11],b[11][11]; char s[11][11]; rep(i,1,n)scanf("%s",s[i]+1); if(s[1][1]=='#'||s[n][n]=='#') { puts("0"); continue; } rep(i,1,n)rep(j,1,n)a[i][j]=s[i][j]=='.'; while(true) { rep(i,1,n)rep(j,1,n)b[i][j]=0; b[n][n]=1; per(i,n,1)per(j,n,1)if(a[i][j]) { if(i