#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char s[N][N];
int q[N][N];
int vis[N][N];
int n;
int dx[2] = {0, 1};
int dy[2] = {1, 0};
struct Node {
  int x, y;
};
bool dfs(int x, int y) {
  vis[x][y] = 1;
  if (x == n || y == n) return true;
  for (int i = 0; i < 2; i++) {
    int tx = x + dx[i], ty = y + dy[i];
    if (tx <= n && ty <= n && q[tx][ty] == 1) {
      return dfs(tx, ty);
    }
  }
  return false;
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    memset(vis[i], 0, (n + 1) * sizeof(int));
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) q[i][j] = s[i][j] - '0';
  int ok = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (vis[i][j]) continue;
      if (q[i][j] == 1) {
        bool t = dfs(i, j);
        if (!t) {
          puts("NO");
          return;
        }
      }
    }
  puts("YES");
}
int main() {
  int T = 1;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
