#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<string> v;
    for (int i = 0; i < n; i++) {
      string temp;
      cin >> temp;
      v.push_back(temp);
    }
    string poss = "YES";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (v[i][j] == '1') {
          if (j + 1 >= n || i + 1 >= n)
            continue;
          else if (v[i][j + 1] == '1' || v[i + 1][j] == '1')
            continue;
          else {
            poss = "NO";
            break;
          }
        }
      }
      if (poss == "NO") break;
    }
    cout << poss << endl;
  }
  return 0;
}
