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