#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    bool b = 0;
    string a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    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][j + 1] == '0' && a[i + 1][j] == '0') {
            b = 1;
            break;
          }
        }
      }
      if (b) break;
    }
    b ? cout << "NO" << endl : cout << "YES" << endl;
  }
  return 0;
}
