#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, flag = 0;
    cin >> n;
    char a[n][n];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (a[i][j] == '1') {
          if (i != n - 1 && j != n - 1 && a[i + 1][j] == '0' &&
              a[i][j + 1] == '0') {
            cout << "NO" << endl;
            flag = 1;
            break;
          }
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 0) {
      cout << "YES" << endl;
    }
  }
}
