#include <bits/stdc++.h>
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int N = 200005;
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<vector<char>> vec(n + 1, vector<char>(n + 1, '1'));
  for (int i = 0; i < n; i += 1)
    for (int j = 0; j < n; j += 1) cin >> vec[i][j];
  bool ok = true;
  for (int i = n - 1; i > -1; i -= 1) {
    for (int j = n - 1; j > -1; j -= 1) {
      if (vec[i][j] == '1') {
        if (vec[i + 1][j] == '0' && vec[i][j + 1] == '0') {
          ok = false;
          break;
        }
      }
    }
    if (!ok) break;
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
