#include <bits/stdc++.h>
using namespace std;
int t, n;
char arr[55][55];
bool v[55][55];
bool bisa() {
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      if (i == n - 1 || j == n - 1) {
        if (arr[i][j] == '1') v[i][j] = 1;
      } else {
        if (arr[i][j] == '1') {
          if (v[i + 1][j] || v[i][j + 1])
            v[i][j] = 1;
          else
            return false;
        }
      }
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> arr[i][j];
      }
    }
    memset(v, false, sizeof(v));
    if (bisa())
      cout << "YES\n";
    else
      cout << "NO\n";
  }
  return 0;
}
