#include <bits/stdc++.h>
using namespace std;
bool check(vector<string> &v, int i, int j) {
  int n = (int)v.size();
  if (i == n - 1 || j == n - 1) {
    return true;
  }
  if (v[i + 1][j] == '1' || v[i][j + 1] == '1') {
    return true;
  }
  return false;
}
void solve() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (string &s : v) cin >> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i][j] == '1' && !check(v, i, j)) {
        cout << "NO\n";
        return;
      }
    }
  }
  cout << "YES\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
