#include <bits/stdc++.h>
using namespace std;
int maxint = numeric_limits<int>::max();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long bino(int n, int m) {
  long long j = 1;
  for (int i = 0; i < m; i++) j = j * (n - i) / (i + 1);
  return j;
}
long long int fast_power(long long int a, long long int x) {
  if (x == 0)
    return 1;
  else if (x == 1)
    return a;
  else {
    long long int R = fast_power(a, x >> 1);
    if (!(x & 1))
      return R * R;
    else
      return R * a * R;
  }
}
bool cmp(pair<char, long long int> &a, pair<char, long long int> &b) {
  return a.second > b.second;
}
long double distance1(long long int x1, long long int y1, long long int x2,
                      long long int y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
}
long long binpoww(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
const int N = 1e6 + 5;
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void add_edge(vector<int> adj[], int u, int v) { adj[u].push_back(v); }
void dfsutil(int u, vector<int> adj[], vector<bool> &visited, int s) {
  visited[u] = true;
  cout << u << " ";
  if (u == s) {
    cout << "Yes";
    exit(0);
  }
  for (int i = 0; i < adj[u].size(); i++)
    if (visited[adj[u][i]] == false) dfsutil(adj[u][i], adj, visited, s);
}
void dfs(vector<int> adj[], int v, int s) {
  vector<bool> visited(v, false);
  for (int u = 1; u <= v; u++) {
    if (visited[u] == false && adj[u].size() > 0) dfsutil(u, adj, visited, s);
  }
}
void prin(vector<int> adj[], int n) {
  for (long long int i = 0; i < n + 1; i++) {
    cout << i << " ";
    for (auto x : adj[i]) cout << "->" << x;
    cout << endl;
  }
}
int bfs(vector<int> adj[], int n, int s) {
  int visited[n + 1];
  for (long long int i = 1; i < n + 1; i++) visited[i] = 0;
  list<int> queue;
  visited[s]++;
  queue.push_back(s);
  vector<int>::iterator i;
  while (!queue.empty()) {
    if (visited[s] == 2) return s;
    s = queue.front();
    queue.pop_front();
    for (i = adj[s].begin(); i != adj[s].end(); ++i) {
      if (visited[*i] != 2) {
        visited[*i]++;
        queue.push_back(*i);
      }
    }
  }
  return 1;
}
void solve() {
  long long int n;
  cin >> n;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == '1') {
        int flag = 0;
        if (i == n - 1 || j == n - 1) {
          flag = 1;
        } else if (a[i + 1][j] == '1' || a[i][j + 1] == '1') {
          flag = 1;
        }
        if (flag == 0) {
          cout << "NO" << endl;
          return;
        }
      }
    }
  }
  cout << "YES" << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
