#include using namespace std; using ll = long long; using PII = pair; const int N = 1e5 + 5, mod = 1e9 + 7; int T, n; char s[20][20]; bool vis[20][20]; PII pre[20][20]; bool bfs() { queue q; q.push({0, 0}); if(s[0][0] == '#') return false; vis[0][0] = vis[n - 1][n - 1] = 0; while(q.size()) { auto t = q.front(); q.pop(); auto x = t.first, y = t.second; if(x == y && x == n - 1) { memset(vis, 0, sizeof vis); while(x || y) { vis[x][y] = 1; x = pre[x][y].first; y = pre[x][y].second; } return true; } if(y < n - 1 && !vis[x][y + 1] && s[x][y + 1] != '#') { q.push({x, y + 1}); pre[x][y + 1] = {x, y}; vis[x][y + 1] = 1; } if(x < n - 1 && !vis[x + 1][y] && s[x + 1][y] != '#') { q.push({x + 1, y}); pre[x + 1][y] = {x, y}; vis[x + 1][y] = 1; } } memset(vis, 0, sizeof vis); return false; } int main() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> T; while(T--) { cin >> n; memset(vis, 0, sizeof vis); for(int i = 0; i < n; i++) cin >> s[i]; int res = bfs() + bfs(); cout << res << endl; } return 0; }