#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, i, j, m, k, c = 0;
  cin >> n;
  for (k = 0; k < n; k++) {
    cin >> m;
    int a[m][m];
    for (i = 0; i < m; i++) {
      string s;
      cin >> s;
      for (j = 0; j < m; j++) {
        a[i][j] = s[j] - 48;
      }
    }
    for (i = 0; i < m - 1; i++) {
      for (j = 0; j < m - 1; j++) {
        if (a[i][j] == 1 && a[i][j + 1] != 1 && a[i + 1][j] != 1) {
          c = 1;
          goto bb;
        } else
          c = 0;
      }
    }
  bb:
    if (c == 0)
      cout << "YES";
    else if (c == 1)
      cout << "NO";
    cout << "\n";
    c = 0;
  }
  return 0;
}
