#include <bits/stdc++.h>
using namespace std;
long long power(long long val, long long deg, long long m) {
  if (!deg) return 1 % m;
  if (deg & 1) return power(val, deg - 1, m) * val % m;
  long long res = power(val, deg >> 1, m);
  return (res * res) % m;
}
bool check(bool mat[][50], int n) {
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (mat[i][j] == 1) {
        if (!(mat[i + 1][j] == 1 || mat[i][j + 1] == 1)) return false;
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    bool mat[n][50];
    char c;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> c;
        mat[i][j] = c - '0';
      }
    }
    if (check(mat, n))
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
