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