#include <bits/stdc++.h>
using namespace std;
int a[55][55];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof a);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        char c;
        cin >> c;
        a[i][j] = c - '0';
      }
    }
    bool ok = true;
    for (int i = n - 1; i >= 1; --i) {
      for (int j = n - 1; j >= 1; --j) {
        if (a[i][j] && !a[i][j + 1] && !a[i + 1][j]) {
          ok = false;
          break;
        }
      }
      if (ok == false) break;
    }
    if (ok == false)
      cout << "NO" << '\n';
    else
      cout << "YES" << '\n';
  }
  return 0;
}
