#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 1;
int t;
int n;
int a[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) {
        char c;
        cin >> c;
        a[i][j] = (c == '1');
      }
    for (int i = 0; i < n - 1; ++i)
      for (int j = 0; j < n - 1; ++j)
        if (a[i][j] && !a[i + 1][j] && !a[i][j + 1]) {
          cout << "NO\n";
          goto END;
        }
    cout << "YES\n";
  END:;
  }
}
