#include <bits/stdc++.h>
using namespace std;
bool ans(string* arr, int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i][j] == '1') {
        if (j == n - 1 || arr[i][j + 1] == '1') {
          continue;
        } else if (i == n - 1 || arr[i + 1][j] == '1') {
          continue;
        } else
          return false;
      }
    }
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string* arr = new string[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    bool myans = ans(arr, n);
    if (myans)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
