#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> #include<random> #include<unordered_set> #include<unordered_map> using namespace std; int r[200][200]; int t; int main(){ cin >> t; while (t--){ int n; scanf("%d", &n); for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ scanf("%d", &r[i][j]); } } bool ng = false; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ if (i&&r[i - 1][j] == r[i][j]){ ng = true; } if (j&&r[i][j - 1] == r[i][j]){ ng = true; } } } if (ng){ puts("No"); } else{ puts("Yes"); } } return 0; }