#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, b = 0;
    cin >> n;
    string s, t;
    vector<string> a;
    for (int i = 0; i < n; i++) {
      cin >> t;
      a.push_back(t);
    }
    for (int i = 0; i < n - 1; i++) {
      s = a[i];
      t = a[i + 1];
      for (int j = 0; j < n - 1; j++) {
        if (s[j] == '1') {
          if (s[j + 1] == '0' and t[j] == '0') {
            b++;
            cout << "NO" << endl;
            break;
          }
        }
      }
      if (b > 0) {
        break;
      }
    }
    if (b == 0) {
      cout << "YES" << endl;
    }
  }
  return 0;
}
