#include <bits/stdc++.h>
using namespace std;
const unsigned seed =
    std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
const int MOD = 998244353;
void solve() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  bool f = false;
  for (int i = 0; i + 1 < n; i++)
    for (int j = 0; j + 1 < n; j++) {
      if (s[i][j] == '0' || s[i][j + 1] == '1' || s[i + 1][j] == '1')
        continue;
      else
        f = true;
    }
  if (f)
    cout << "NO\n";
  else
    cout << "YES\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int T = 1;
  cin >> T;
  for (int i = 1; i <= T; i++) {
    solve();
  }
  cout.flush();
  return 0;
}
