#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  cin >> tt;
  while ((tt)--) {
    long long n;
    cin >> n;
    vector<string> s(n);
    for (long long i = 0; i < (n); ++i) cin >> s[i];
    long long ans = 1;
    for (long long i = 0; i < (n); ++i) {
      for (long long j = 0; j < (n); ++j) {
        long long use = 0;
        if (s[i][j] == '1') {
          if (i == n - 1 or j == n - 1) continue;
          if (i + 1 < n and s[i + 1][j] == '1') use = 1;
          if (j + 1 < n and s[i][j + 1] == '1') use = 1;
          ans &= use;
        }
      }
    }
    if (ans) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
}
