#include <bits/stdc++.h>
using namespace std;
char grid[55][55];
int T, N;
int main() {
  cin >> T;
  for (int QQQ = 0; QQQ < T; QQQ++) {
    cin >> N;
    bool works = true;
    for (int i = 0; i < N; i++) cin >> grid[i];
    for (int r = 0; r < N - 1; r++)
      for (int c = 0; c < N - 1; c++)
        if (grid[r][c] == '1' &&
            (grid[r + 1][c] == '0' && grid[r][c + 1] == '0'))
          works = false;
    if (works)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  return 0;
}
