#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    vector<string> a(n);
    bool flag = true;
    for (int i = 0; i <= n - 1; i++) cin >> a[i];
    for (int i = 0; i <= n - 1; i++) {
      for (int j = 0; j <= n - 1; j++) {
        if (i == n - 1 || j == n - 1) continue;
        if (a[i][j] == '1') {
          if (a[i + 1][j] == '0' && a[i][j + 1] == '0') {
            flag = false;
            break;
          }
        }
      }
    }
    if (flag)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
