#include <bits/stdc++.h>
using namespace std;
long long i, j, n, t;
char c;
string res;
int main() {
  cin >> t;
  while (t > 0) {
    t--;
    cin >> n;
    int a[n][n];
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        cin >> c;
        a[i][j] = c - '0';
      }
    }
    res = "YES";
    for (i = 0; i < n - 1; i++) {
      for (j = 0; j < n - 1; j++) {
        if ((a[i][j] == 1) && (a[i][j + 1] == 0) && (a[i + 1][j] == 0))
          res = "NO";
      }
    }
    cout << res << "\n";
  }
  return 0;
}
