#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
int n;
void solve() {
  cin >> n;
  vector<vector<char>> g(n, vector<char>(n));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) cin >> g[i][j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (g[i][j] == '1') {
        if (i != n - 1 && j != n - 1 && g[i + 1][j] != '1' &&
            g[i][j + 1] != '1') {
          cout << "NO\n";
          return;
        }
      }
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
