#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  for (int q = 1; q <= t; q++) {
    int n;
    cin >> n;
    vector<string> gr, vis;
    string s;
    for (int i = 0; i < n; i++) {
      cin >> s;
      gr.push_back(s);
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < n - 1; j++) {
        if (gr[i][j] == '1') {
          if (gr[i + 1][j] == '1' || gr[i][j + 1] == '1') {
            gr[i][j] = '9';
          }
        }
      }
    }
    bool fl = true;
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < n - 1; j++) {
        if (gr[i][j] == '1') fl = false;
      }
    }
    cout << (fl ? "YES\n" : "NO\n");
  }
  return 0;
}
