#include <bits/stdc++.h>
using namespace std;
long double pi = 3.14159265358979323846;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
unsigned long long binpow(unsigned long long n, unsigned long long po) {
  unsigned long long res = 1;
  while (po > 0) {
    if (po % 2) {
      res *= n;
      po--;
    } else {
      n *= n;
      po /= 2;
    }
  }
  return res;
}
vector<long long> al[500005];
unsigned long long vis[500005], color[500005];
int main() {
  unsigned long long t;
  cin >> t;
  while (t--) {
    unsigned long long n, flag = 0;
    cin >> n;
    string a[n];
    for (unsigned long long i = 0; i < n; i++) cin >> a[i];
    for (unsigned long long i = 0; i < n; i++)
      for (unsigned 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')
            flag = 1;
    if (flag == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
