#include <bits/stdc++.h>
int main() {
  int t, n, row, col, i, j, test = 1, a[52][52];
  char str[52][52], ch;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%s", str[i]);
      for (j = 0; j < n; j++) {
        ch = str[i][j];
        a[i][j] = ch - '0';
      }
    }
    for (row = 0; row < n - 1; row++) {
      for (col = 0; col < n - 1; col++) {
        if (a[row][col] == 1) {
          if (a[row + 1][col] == 0 && a[row][col + 1] == 0) {
            test = 0;
            break;
          }
        }
      }
      if (!test) break;
    }
    printf("%s\n", test ? "YES" : "NO");
    test = 1;
  }
  return 0;
}
