#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 100000 + 10;
const int M = 100000 + 10;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3fffffff;
const long long LINF = 0x3fffffffffffffff;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
char mp[60][60] = {0};
void solve() {
  int n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (mp[i][j] == '1') {
        if (mp[i][j + 1] != '1' && mp[i + 1][j] != '1') {
          puts("NO");
          return;
        }
      }
    }
  }
  puts("YES");
  return;
}
int main() {
  for (long long t = read(); t; t--) solve();
  return 0;
}
