#include using namespace std; const int N = 15; int t, n, ans; bool a[N][N]; string s[N]; int read() { int x = 0, p = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') p = -1; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c & 15); return x * p; } void write(int x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } void writeln(int x) { if (x < 0) { putchar('-'); x = -x; } write(x); putchar('\n'); } void work1() { memset(a, 0, sizeof a); a[1][1] = (s[1][1] == '.'); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i + j == 2) continue; if (s[i][j] == '.') a[i][j] = a[i - 1][j] | a[i][j - 1]; } } } void work2() { int x = n, y = n; while (x + y > 3) { if (a[x - 1][y]) x--; else y--; s[x][y] = '#'; } } int main() { t = read(); while (t--) { n = read(); for (int i = 1; i <= n; i++) { cin >> s[i]; s[i] = " " + s[i]; } work1(); if (!a[n][n]) { puts("0"); continue; } work2(); work1(); puts(a[n][n] ? "2" : "1"); } return 0; }