#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void zz() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int32_t main() {
  zz();
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s[n];
    for (long long i = 0; i < n; i++) {
      cin >> s[i];
    }
    bool b = 0;
    for (long long i = 0; i < n - 1; i++) {
      for (long long j = 0; j < n - 1; j++) {
        if (s[i][j] == '1') {
          if (s[i + 1][j] == '1' || s[i][j + 1] == '1') {
          } else {
            b = 1;
            break;
          }
        }
      }
      if (b) break;
    }
    if (!b)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
