#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<string> v(n);
    for (auto& i : v) cin >> i;
    bool state = true;
    for (int i = n - 2; i >= 0; i--) {
      for (int j = n - 2; j >= 0; --j) {
        if (v[i][j] == '1' && v[i + 1][j] == '0' && v[i][j + 1] == '0')
          state = false;
      }
    }
    if (state)
      cout << "Yes" << '\n';
    else
      cout << "No" << '\n';
  }
}
