#include typedef long long ll; typedef std::pair pii; const int N = 10 + 10; const int inf = 0x3f3f3f3f; const int mod = 10 + 7; const double eps = 1e-9; char a[N][N]; int dx[4] = {1, 0, 0, 1}, dy[4] = {0, 1, 1, 0}; int n; bool st[N][N]; bool dfs1(int x, int y) { //std::cout << x << ' ' << y << std::endl; if(x == y && y == n - 1) return true; for(int i = 0; i < 2; i++) { int xx = x + dx[i], yy = y + dy[i]; if(xx < 0 || xx >= n || yy < 0 || yy >= n) continue; if(st[xx][yy]) continue; if(a[xx][yy] == '#')continue; st[xx][yy] = 1; if(dfs1(xx, yy)) return true; st[xx][yy] = 0; } return false; } bool dfs2(int x, int y) { if(x == y && y == n - 1) return true; for(int i = 2; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if(xx < 0 || xx >= n || yy < 0 || yy >= n) continue; if(st[xx][yy]) continue; if(a[xx][yy] == '#')continue; st[xx][yy] = 1; if(dfs2(xx, yy)) return true; st[xx][yy] = 0; } return false; } int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t; std::cin >> t; while(t--) { memset(st, 0, sizeof st); scanf("%d", &n); for(int i = 0; i < n;i ++) { scanf("%s", a[i]); } int ans = 0; if(dfs1(0, 0))ans ++; st[n - 1][n - 1] = 0; if(dfs2(0, 0)) ans ++; if(a[0][0] == '#' || a[n - 1][n - 1] == '#') ans = 0; printf("%d\n", ans); } }