#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int i, j, n, g = 0;
    cin >> n;
    string s[n];
    for (i = 0; i < n; i++) cin >> s[i];
    for (i = 0; i < n - 1; i++) {
      for (j = 0; j < n - 1; j++) {
        if (s[i][j] == '1' && s[i + 1][j] == '0' && s[i][j + 1] == '0') {
          g++;
          break;
        }
      }
      if (g != 0) break;
    }
    if (g == 0) {
      cout << "YES"
           << "\n";
      ;
    } else
      cout << "NO"
           << "\n";
    ;
  }
  return 0;
}
