#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const int mod = 1e9 + 7;
void D(vector<int> a) {
  for (int i : a) cout << i << " ";
  cout << endl;
}
void solve() {
  int n;
  cin >> n;
  vector<vector<char>> a(n, vector<char>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == '1') {
        if (i + 1 < n && j + 1 < n &&
            !(a[i + 1][j] == '1' || a[i][j + 1] == '1')) {
          cout << "NO" << endl;
          return;
        }
      }
    }
  }
  cout << "YES" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
