#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n + 17][n + 17];
    char ch[n + 17][n + 17];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        cin >> ch[i][j];
        a[i][j] = ch[i][j] - 48;
      }
    }
    for (int i = 1; i < n; i++) {
      for (int j = 1; j < n; j++) {
        if (a[i][j] == 1) {
          if (a[i + 1][j] == 0 && a[i][j + 1] == 0) {
            cout << "NO" << endl;
            goto wow;
          }
        }
      }
    }
    cout << "YES" << endl;
  wow:;
  }
  return 0;
}
