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