#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (s[i][j] == '1') {
        if (s[i + 1][j] == '1' || s[i][j + 1] == '1')
          continue;
        else {
          cout << "NO\n";
          return;
        }
      }
    }
  }
  cout << "YES\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
