#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string str[n + 1];
    for (long long int i = 0; i < n; i++) cin >> str[i];
    long long int flag = false;
    for (long long int i = n - 2; i >= 0; i--) {
      for (long long int j = n - 2; j >= 0; j--) {
        if (str[i][j] == '1') {
          if (str[i + 1][j] == '0' && str[i][j + 1] == '0') {
            flag = true;
          }
        }
      }
    }
    if (flag)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
