#include #define rep(i, n) for(int i = 0; i < (int)(n); i ++) #define rep1(i, n) for(int i = 1; i <= (int)(n); i ++) #define MP make_pair using namespace std; typedef long long LL; typedef pair PII; const int MOD = 998244353; int n; char ch[15][15]; LL dp[15][15]; LL calc(int sx, int sy, int tx, int ty) { memset(dp, 0, sizeof(dp)); dp[sx][sy] = 1; rep(i, n) rep(j, n) { if(ch[i][j] == '#') dp[i][j] = 0; dp[i + 1][j] += dp[i][j]; dp[i][j + 1] += dp[i][j]; } return dp[tx][ty]; } void solve() { cin >> n; rep(i, n) cin >> ch[i]; LL ans = calc(0, 1, n - 2, n - 1) * calc(1, 0, n - 1, n - 2) - calc(0, 1, n - 1, n - 2) * calc(1, 0, n - 2, n - 1); LL a2 = calc(0, 0, n - 1, n - 1); printf("%d\n", a2 ? (ans ? 2 : 1) : 0); } int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T --) solve(); return 0; }