#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  ;
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<string> arr(n);
    for (int(i) = 0; (i) < (n); ++(i)) cin >> arr[i];
    bool flag = true;
    for (int(i) = 0; (i) < (n - 1); ++(i)) {
      for (int(j) = 0; (j) < (n - 1); ++(j)) {
        if (arr[i][j] == '1') {
          if (arr[i + 1][j] == '0' && arr[i][j + 1] == '0') {
            flag = false;
          }
        }
      }
    }
    cout << (flag ? "YES" : "NO") << endl;
  }
  return 0;
}
