#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long z = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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];
    if (n == 1)
      cout << "YES\n";
    else {
      long long c = 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] == '0' && s[i][j + 1] == '0') {
              c++;
              break;
            }
          }
        }
      }
      if (c)
        cout << "NO\n";
      else
        cout << "YES\n";
    }
  }
}
