#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  char a[n][n];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 0; i < n - 1; i++) {
    for (long long int j = 0; j < n - 1; j++) {
      if (a[i][j] == '1') {
        if (a[i + 1][j] == '0' and a[i][j + 1] == '0') {
          cout << "NO\n";
          return;
        }
      }
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}
