#include <iostream> #include <stdio.h> #include <cstring> #define FOR(i,a,b) for (int i=(a); i<=(b); ++i) #define FORR(i,a,b) for (int i=(a); i>=(b); --i) #define REP(i,b) for (int i=0; i<(b); ++i) #define input stdin #define output stdout #define assign freopen #define endl '\n' #define sz(x) (int) x.size() #define div / #define mod % #define fillchar(x,y,z) memset(x,z,y) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define sqr(x) ((x)*(x)) typedef long long int64; typedef unsigned long long qword; typedef void procedure; using namespace std; int n; int a[200][200]; procedure Input() { cin >> n; fillchar(a,sizeof(a),255); FOR(i,1,n) FOR(j,1,n) cin >> a[i][j]; } procedure Solve() { FOR(i,1,n) FOR(j,1,n) if (a[i+1][j]==a[i][j]||a[i][j+1]==a[i][j]) { cout << "No" << endl; return; } cout << "Yes" << endl; } int main() { #ifdef meomeomeooooo assign("input.txt","r",input); //assign("output.txt","w",output); #endif // meomeomeooooo iostream::sync_with_stdio(false); cin.tie(0); int t; cin >> t; FOR(i,1,t) { Input(); Solve(); } return 0; }