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