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