#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H), debug_out(T...);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < (int)n; i++) cin >> v[i];
    bool ok = 1;
    for (int i = 0; i < (int)n - 1; i++) {
      for (int j = 0; j < (int)n - 1; j++) {
        if (v[i][j] == '1' && !(v[i + 1][j] == '1' || v[i][j + 1] == '1')) {
          ok = 0;
          break;
        }
      }
    }
    if (ok)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
