#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
void solve() {
  int n, o = 0;
  char x;
  cin >> n;
  int M[n][n];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> x;
      if (x == '0')
        M[i][j] = 0;
      else {
        M[i][j] = 1;
        o++;
      }
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (M[i][j] == 1) {
        if (i == n - 1 || j == n - 1 || M[i + 1][j] == 1 || M[i][j + 1] == 1)
          o--;
      }
    }
  if (o == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) solve();
}
