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