#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    int fl = 0;
    vector<string> a(n);
    for (int j = 0; j < n; j++) cin >> a[j];
    int vis[n][n];
    memset(vis, 0, sizeof(vis));
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (a[j][k] == '0')
          continue;
        else {
          if (j == n - 1 || k == n - 1) {
            vis[j][k] = 1;
            continue;
          } else if (a[j + 1][k] == '1' || a[j][k + 1] == '1') {
            vis[j][k] = 1;
            continue;
          }
        }
      }
    }
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (a[j][k] == '1') {
          if (vis[j][k] != 1) {
            fl++;
            break;
          }
        }
      }
      if (fl != 0) break;
    }
    if (fl == 0)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
