#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
void solve() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  char a[55][55];
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    memset(a, 0, sizeof(a));
    for (int j = 0; j < n; j++) {
      cin >> a[j];
    }
    int c = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if ((a[i][j] == '1') && (a[i + 1][j] == '0') && (a[i][j + 1] == '0')) {
          c = 0;
          break;
        }
      }
    }
    if (c == 1) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
