#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    char ch[n][n];
    bool b = true;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) cin >> ch[i][j];
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < n - 1; j++) {
        if (ch[i][j] == '1' && ch[i][j + 1] == '0' && ch[i + 1][j] == '0') {
          b = false;
          break;
        }
      }
      if (!b) break;
    }
    if (b)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
