#include <bits/stdc++.h>
using namespace std;
const long long INF64 = (long long)(1e18) + 100;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    char arr[n][n];
    for (long long int i = 0; i < n; i++)
      for (long long int j = 0; j < n; j++) cin >> arr[i][j];
    int flag = 1;
    for (long long int i = 0; i < n - 1; i++) {
      for (long long int j = 0; j < n - 1; j++) {
        if (arr[i][j] == '1') {
          if (arr[i + 1][j] == '0' && arr[i][j + 1] == '0') {
            flag = 0;
            break;
          }
        }
      }
    }
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
