#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
bool solve() {
  long long n;
  cin >> n;
  vector<string> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  for (long long i = (0); i < (n - 1); i++)
    for (long long j = (0); j < (n - 1); j++)
      if (a[i][j] == '1') {
        if (a[i + 1][j] == '0' && a[i][j + 1] == '0') return false;
      }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tc;
  cin >> tc;
  while (tc--) {
    cout << (solve() ? "YES" : "NO") << endl;
  }
}
