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