#include <bits/stdc++.h>
using namespace std;
const long long MOD = pow(10, 9) + 7;
const long long MAX = LONG_LONG_MAX;
void solve() {
  int n;
  cin >> n;
  vector<string> a(n, "");
  for (int i = 0; i < n; i += 1) cin >> a[i];
  for (int i = 0; i < n; i += 1) {
    for (int j = 0; j < n; j += 1) {
      if (a[i][j] == '1') {
        if (i == n - 1 || j == n - 1) {
          continue;
        }
        if (a[i + 1][j] == '1' || a[i][j + 1] == '1') {
          continue;
        } else {
          cout << "NO";
          return;
        }
      }
    }
  }
  cout << "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t > 0) {
    solve();
    t--;
    cout << endl;
  }
}
