#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
void solve() {
    int x;
    cin >> x;
    vector <string> A(x);
    for(int i = 0; i < x; i++) {
        for(int j = 0; j < x; j++) {
            char c;
            cin >> c;
            A[i].push_back(c);
        }
    }
    for(int i = 0; i < x - 1; i++) {
        for(int j = 0; j < x - 1; j++) {
            if(A[i][j] == A[i + 1][j] || A[i][j] == A[i][j + 1] || A[i][j] != A[i + 1][j + 1]) {
                cout << "No\n";
                return;
            }
        }
    }
    cout << "Yes\n";
}
int main() {fio; // remove during scanf
    int n;
    cin >> n;
    while(n--) {
        solve();
    }
    return 0;
}