#include #define RAN(v) v.begin(), v.end() #define pb push_back #define lb lower_bound #define ub upper_bound #define I (J + 1) #define J (i + j >> 1) #define P (k << 1) #define S (P ^ 1) using namespace std; typedef long long ll; template inline void upd1(T1& a, const T2& b) { a = a < b ? a : b; } template inline void upd2(T1& a, const T2& b) { a = b < a ? a : b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } struct Ano { operator ll() { ll x = 0, y = 0, c = getchar(); while (c < 48) { y = c == 45; c = getchar(); } while (c > 47) { x = x*10 + c-48; c = getchar(); } return y ? -x : x; } } buf; constexpr int N = 12; int n; bool vis[N][N]; char a[N][N]; bool dfs(int i, int j) { if (i > n || j > n || a[i][j] == '#' || vis[i][j]) return 0; if (i == n && j == n) return 1; if (i != 1 || j != 1) vis[i][j] = 1; if (dfs(i, j + 1)) return 1; if (dfs(i + 1, j)) return 1; return 0; } int main() { for (int q = buf; q; --q) { memset(vis, 0, sizeof vis); n = buf; for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1); int s = 0; if (dfs(1, 1)) { s = 1 + dfs(1, 1); } printf("%d\n", s); } }