#include <bits/stdc++.h>
using namespace std;
bool pr(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    char a[51][51];
    bool f = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < n - 1; j++) {
        if ((a[i][j] == '1' && (a[i + 1][j] == '0' && a[i][j + 1] == '0'))) {
          f = true;
          break;
        }
      }
      if (f == true) {
        cout << "NO" << endl;
        break;
      }
    }
    if (f == false) cout << "YES" << endl;
  }
}
