#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int testcase = 1;
  cin >> testcase;
  while (testcase--) {
    solve();
  }
  return 0;
}
void solve() {
  int n;
  cin >> n;
  string square[n];
  for (int i = 0; i < n; i++) {
    cin >> square[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (square[i][j] == '1') {
        if (i == n - 1 || j == n - 1) continue;
        if (square[i + 1][j] != '1' && square[i][j + 1] != '1') {
          cout << "NO" << endl;
          return;
        }
      }
    }
  }
  cout << "YES" << endl;
  return;
}
