#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string mat[n];
    for (long long i = 0; i < n; i++) cin >> mat[i];
    bool ans = 1;
    for (long long i = 0; i < n - 1; i++) {
      for (long long j = 0; j < n - 1; j++) {
        if (mat[i][j] == '1' && mat[i + 1][j] == '0' && mat[i][j + 1] == '0')
          ans = 0;
      }
    }
    if (ans)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
