#include <bits/stdc++.h>
using namespace std;
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  typename map<first, second>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
vector<vector<char> > a;
int32_t main() {
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  a.clear();
  while (t--) {
    long long n;
    cin >> n;
    a.clear();
    a.resize(n, vector<char>(n, '0'));
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        cin >> a[i][j];
      }
    }
    long long f = 1;
    for (long long i = n - 1; i >= 0; i--) {
      for (long long j = n - 1; j >= 0; j--) {
        if (i == (n - 1)) {
          if (j == (n - 1)) {
          } else {
          }
        } else {
          if (j == (n - 1)) {
          } else {
            if (a[i][j] == '1') {
              if (a[i][j + 1] == ('1')) {
              } else if (a[i + 1][j] == '1') {
              } else {
                f = 0;
              }
            }
          }
        }
      }
    }
    if (f == 0) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
  return 0;
}
