#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    char sq[52][52] = {0};
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        cin >> sq[i][j];
      }
    bool ans = true;
    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j < n - 1; j++) {
        if (sq[i][j] == '1') {
          if (sq[i][j + 1] != '1' && sq[i + 1][j] != '1') {
            ans = false;
          }
        }
      }
    cout << (ans ? "YES\n" : "NO\n");
  }
  return 0;
}
