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