#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long max(int a, long long b) { return max((long long)a, b); }
long long min(int a, long long b) { return min((long long)a, b); }
long long min(long long a, int b) { return min(a, (long long)b); }
long long max(long long a, int b) { return max(a, (long long)b); }
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long modu(long long k) {
  if (k >= 0)
    return k;
  else
    return -k;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<string> arr(n);
    long long dp[n][n];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) dp[i][j] = 3;
    }
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long cnt = 0;
    for (long long j = 0; j < n; j++) {
      if (arr[n - 1][j] == '1') dp[n - 1][j] = 4;
    }
    for (long long i = 0; i < n; i++) {
      if (arr[i][n - 1] == '1') dp[i][n - 1] = 4;
    }
    for (long long i = n - 2; i >= 0; i--) {
      for (long long j = n - 2; j >= 0; j--) {
        if (arr[i][j] == '1') {
          if (dp[i + 1][j] == 4 || dp[i][j + 1] == 4) {
            dp[i][j] = 4;
          }
        }
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        if (arr[i][j] == '1' && dp[i][j] == 3) {
          cnt++;
          break;
        }
      }
    }
    if (cnt == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
