#include <bits/stdc++.h>
using namespace std;
long long n, x, ans, tt;
char c[55][55];
bool ok;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> tt;
  while (tt--) {
    cin >> n;
    ok = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        cin >> c[i][j];
      }
    }
    for (int i = 1; i <= n; ++i) {
      c[i][n + 1] = '1';
      c[n + 1][i] = '1';
    }
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (c[i][j] == '1' && c[i][j + 1] == '0' && c[i + 1][j] == '0') {
          ok = 0;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
    for (int i = 1; i <= n + 1; ++i) {
      for (int j = 1; j <= n + 1; ++j) {
        c[i][j] = 0;
      }
    }
  }
  return 0;
}
