#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int matrix[n][n];
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < n; j++) {
        matrix[i][j] = s[j] - '0';
      }
    }
    bool lehet_e = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (matrix[i][j] == 1) {
          if (matrix[i + 1][j] == 0 && matrix[i][j + 1] == 0) {
            if (i != n - 1 && j != n - 1) {
              lehet_e = false;
              break;
            }
          }
        }
      }
      if (!lehet_e) {
        cout << "NO" << endl;
        break;
      }
    }
    if (lehet_e) {
      cout << "YES" << endl;
    }
  }
  return 0;
}
