#include using namespace std; int T, n, vis[11][11], d[4][2] = {{0, 1}, {1, 0}}, t[11][11]; char s[11][11]; bool dfs(int x, int y){ vis[x][y] = 1; if(x == n-1 && y == n-1){ t[n-1][n-1] = 0; return 1; } for(int i = 0; i < 2; i++){ int new_x = x + d[i][0], new_y = y + d[i][1], flag = 0; if(new_x < n && new_x >=0 && new_y >= 0 && new_y < n && !vis[new_x][new_y] && s[new_x][new_y] == '.' && !t[new_x][new_y]){ t[new_x][new_y] = 1; flag = dfs(new_x, new_y); if(flag) return 1; vis[new_x][new_y] = 0; t[new_x][new_y] = 0; } } return 0; } int main() { scanf("%d", &T); while(T--){ scanf("%d", &n); int ans = 0; fill(t[0], t[0]+121, 0); for(int i = 0; i < n; ++i) scanf("%s", s[i]); if(s[n-1][n-1] == '#' || s[0][0] == '#') printf("%d\n", ans); else{ while(dfs(0, 0)){ ans++; fill(vis[0], vis[0]+121, 0); } printf("%d\n", ans); } } return 0; }