#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const long long MOD = (long long)(1e9) + (long long)(7);
int arr[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    memset(arr, 0, sizeof(arr));
    int n, m;
    cin >> n;
    m = n;
    vector<string> v(n);
    for (auto &i : v) cin >> i;
    for (int i = 0; i < n; i++) {
      string s = v[i];
      for (int j = 0; j < n; j++) {
        arr[i][j] = s[j] - '0';
      }
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m - 1; j++) {
        if (i == n - 1) {
        } else {
          if (arr[i][j] == 1) {
            if (arr[i + 1][j] == 1 || arr[i][j + 1] == 1) {
            } else {
              ok = false;
              break;
            }
          }
        }
      }
    }
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
