#include <bits/stdc++.h>
using namespace std;
char P[55][55];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> P[i][j];
      }
    }
    int flag = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (P[i][j] == '1') {
          if (i == n - 1 || j == n - 1)
            continue;
          else if (P[i + 1][j] == '1' || P[i][j + 1] == '1')
            continue;
          else {
            cout << "NO\n";
            flag = 1;
            break;
          }
        }
      }
      if (flag == 1) break;
    }
    if (flag == 0) cout << "YES\n";
  }
  return 0;
}
