#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T>
inline T SQR(T a) {
  return a * a;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    char s[n + 2][n + 2];
    for (int i = 0; i < n; i++) scanf("%s", s[i]);
    bool pashe[n + 2][n + 2], niche[n + 2][n + 2];
    memset(pashe, false, sizeof pashe);
    memset(niche, false, sizeof niche);
    for (int i = 0; i < n; i++) {
      bool f = true;
      for (int j = n - 1; j >= 0; j--) {
        pashe[i][j] = f;
        if (s[i][j] == '0')
          f = false;
        else
          f = true;
      }
    }
    for (int j = 0; j < n; j++) {
      bool f = true;
      for (int i = n - 1; i >= 0; i--) {
        niche[i][j] = f;
        if (s[i][j] == '0')
          f = false;
        else
          f = true;
      }
    }
    bool ans = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (s[i][j] == '0') continue;
        if (pashe[i][j] || niche[i][j]) continue;
        ans = false;
      }
    }
    if (ans)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
