#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238460;
int fun(string s, string s1, int n, int n1, int **dp) {
  if (n == 0 || n1 == 0) return 0;
  if (dp[n][n1] != -1) return dp[n][n1];
  if (s[n - 1] == s1[n1 - 1])
    dp[n][n1] = 1 + fun(s, s1, n - 1, n1 - 1, dp);
  else {
    dp[n][n1] = max(fun(s, s1, n, n1 - 1, dp), fun(s, s1, n - 1, n1, dp));
  }
  return dp[n][n1];
}
void solve() {
  int n;
  cin >> n;
  vector<string> dp(n);
  for (int i = 0; i < n; i++) cin >> dp[i];
  bool istrue = true;
  for (int i = n - 2; i >= 0; i--) {
    for (int j = n - 2; j >= 0; j--) {
      if (dp[i][j] == '1' && dp[i + 1][j] == '0' && dp[i][j + 1] == '0')
        istrue = false;
      if (!istrue) break;
    }
    if (!istrue) break;
  }
  if (istrue)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
