#include using namespace std; const int maxn = 15; int T, n; bool f[maxn][maxn], g[25][maxn][maxn]; char s[maxn][maxn]; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", s[i] + 1); } memset(f, 0, sizeof(f)); f[1][1] = s[1][1] == '.'; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) if (s[i][j] == '.') { if (i > 1) f[i][j] |= f[i - 1][j]; if (j > 1) f[i][j] |= f[i][j - 1]; } } if (!f[n][n]) { puts("0"); continue; } memset(g, 0, sizeof(g)); g[2][1][1] = 1; for (int s = 2; s <= 2 * n; s++) { for (int x1 = 1; x1 <= n; x1++) { for (int x2 = 1; x2 <= n; x2++) if (g[s][x1][x2]) { int y1 = s - x1, y2 = s - x2; if (x1 < n && ::s[x1 + 1][y1] == '.') { if (x2 < n && ::s[x2 + 1][y2] == '.') { if (s == 2 * n - 1 || x1 + 1 != x2 + 1) g[s + 1][x1 + 1][x2 + 1] = 1; } if (y2 < n && ::s[x2][y2 + 1] == '.') { if (s == 2 * n - 1 || x1 + 1 != x2) g[s + 1][x1 + 1][x2] = 1; } } if (y1 < n && ::s[x1][y1 + 1] == '.') { if (x2 < n && ::s[x2 + 1][y2] == '.') { if (s == 2 * n - 1 || x1 != x2 + 1) g[s + 1][x1][x2 + 1] = 1; } if (y2 < n && ::s[x2][y2 + 1] == '.') { if (s == 2 * n - 1 || x1 != x2) g[s + 1][x1][x2] = 1; } } } } } if (g[2 * n][n][n]) puts("2"); else puts("1"); } return 0; }