#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    bool flag = false;
    for (int r = 0; r < n - 1; r++) {
      for (int c = 0; c < n - 1; c++) {
        if (arr[r][c] == '1') {
          if (arr[r + 1][c] != '1' && arr[r][c + 1] != '1') {
            cout << "NO" << endl;
            flag = true;
            break;
          }
        }
      }
      if (flag) break;
    }
    if (!flag) cout << "YES" << endl;
  }
  return 0;
}
