#include <bits/stdc++.h>
using namespace std;
template <typename so>
void read(so &x) {
  x = 0;
  char c;
  long long dem = 0;
  for (c = getchar(); c < '0' || c > '9'; c = getchar()) {
    dem++;
    if (dem == 100) return;
  }
  for (; c >= '0' && c <= '9'; c = getchar()) {
    x = x * 10 + c - '0';
  }
}
const long long MaxN = 1e6 + 1e5;
const long long mod = 1e9 + 7;
long long n, k;
bool a[1001][1001];
bool gg[1001][1001];
bool come[1001][1001];
string s;
void input() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> s;
    for (long long j = 1; j <= n; j++) {
      gg[i][j] = s[j - 1] - '0';
      a[i][j] = 0;
      come[i][j] = 0;
    }
  }
  for (long long i = n; i >= 1; i--) {
    for (long long j = n; j >= 1; j--) {
      if (i == n || j == n) {
        continue;
      }
      if (gg[i][j] == 1 && gg[i + 1][j] == 0 && gg[i][j + 1] == 0) {
        cout << "NO" << '\n';
        return;
      }
    }
  }
  cout << "YES" << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) input();
}
