#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int a[55][55];
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof a);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      string tmp;
      cin >> tmp;
      tmp = '#' + tmp;
      for (int j = 1; j <= n; j++) a[i][j] = (!(tmp[j] - '0'));
    }
    bool ok = true;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == 1) continue;
        ok = (a[i + 1][j] == 0 || a[i][j + 1] == 0);
        if (!ok) goto gg;
      }
    }
  gg:
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
