#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, n, i, j, k;
  cin >> T;
  while (T--) {
    cin >> n;
    string str[51];
    for (i = 0; i < n; i++) {
      cin >> str[i];
    }
    if (n == 1) {
      cout << "YES" << endl;
      continue;
    }
    for (i = n - 1; i >= 0; i--) {
      for (j = n - 1; j >= 0; j--) {
        if (str[i][j] == '1') {
          if (i == n - 1 || j == n - 1) str[i][j] = '*';
          k = n - 1;
          int c = 0;
          while (k >= 0) {
            if (str[k][j] == '*') {
              c = 1;
            } else if (str[k][j] == '1' && c == 1) {
              str[k][j] = '*';
            } else if (str[k][j] == '0')
              c = 0;
            k--;
          }
          k = n - 1;
          c = 0;
          while (k >= 0) {
            if (str[i][k] == '*') {
              c = 1;
            } else if (str[i][k] == '1' && c == 1) {
              str[i][k] = '*';
            } else if (str[i][k] == '0')
              c = 0;
            k--;
          }
        }
      }
    }
    for (i = n - 1; i >= 0; i--) {
      for (j = n - 1; j >= 0; j--) {
        if (str[i][j] == '1') {
          if (i == n - 1 || j == n - 1) str[i][j] = '*';
          k = n - 1;
          int c = 0;
          while (k >= 0) {
            if (str[i][k] == '*') {
              c = 1;
            } else if (str[i][k] == '1' && c == 1) {
              str[i][k] = '*';
            } else if (str[i][k] == '0')
              c = 0;
            k--;
          }
          k = n - 1;
          c = 0;
          while (k >= 0) {
            if (str[k][j] == '*') {
              c = 1;
            } else if (str[k][j] == '1' && c == 1) {
              str[k][j] = '*';
            } else if (str[k][j] == '0')
              c = 0;
            k--;
          }
        }
      }
    }
    int cnt = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if (str[i][j] == '1') {
          cnt++;
        }
      }
    }
    if (cnt == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
