#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n;
  long long a[n][n];
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < n; j++) {
      a[i][j] = s[j] - '0';
    }
  }
  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 1) {
        if (i < n - 1 && j < n - 1) {
          ok = ok && (a[i + 1][j] == 1 || a[i][j + 1] == 1);
        }
      }
    }
  }
  if (ok) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
