#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <typename T>
T gcd(T a, T b) {
  return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
  return (a * (b / gcd(a, b)));
}
void run() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  run();
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    string arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (int i = 0; i < n; i++) {
      if (arr[i][n - 1] == '1') arr[i][n - 1] = '5';
    }
    for (int i = 0; i < n; i++) {
      if (arr[n - 1][i] == '1') arr[n - 1][i] = '5';
    }
    for (int i = n - 1; i >= 0; i--) {
      for (int j = n - 2; j >= 0; j--) {
        if (arr[i][j] == '1') {
          if (i != n - 1) {
            if (arr[i][j + 1] == '5' or arr[i + 1][j] == '5') arr[i][j] = '5';
          } else if (i == n - 1) {
            if (arr[i][j + 1] == '5') arr[i][j] = '5';
          }
        }
      }
    }
    int flag = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (arr[i][j] == '1') {
          flag = 1;
          break;
        }
      }
    }
    if (flag)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
