#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int r = 0; r < t; r++) {
    int n, x;
    string s;
    cin >> n;
    vector<vector<bool> > a;
    a.resize(n);
    for (int i = 0; i < n; i++) {
      a[i].resize(n);
      cin >> s;
      for (int k = 0; k < n; k++) {
        x = s[k] - '0';
        if (x == 1) {
          a[i][k] = true;
        } else
          a[i][k] = false;
      }
    }
    bool b = true;
    for (int i = 0; i < n - 1; i++) {
      for (int k = 0; k < n - 1; k++) {
        if (a[i][k] && !(a[i + 1][k] | a[i][k + 1])) {
          b = false;
          break;
        }
      }
      if (!b) break;
    }
    if (b) {
      cout << "YES\n";
    } else
      cout << "NO\n";
  }
}
