#define YUKICODER // #define CODEFORCES #include #define rep(i, n) for(int i=0;i<(int)(n);i++) #define pb push_back #define pob pop_back #define eb emplace_back #define nall(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define accu accumulate #define bs binary_search #define lb lower_bound #define ub upper_bound #define maxe max_element #define mine min_element #ifdef CODEFORCES #define yes cout<<"YES\n" #define no cout<<"NO\n" #define yesno(a) cout<<(a?"YES\n":"NO\n") #define yesnoout(a, b) cout<<(a?"YES\n":"NO")<<(a?b:"")<<"\n" #else #define yes cout<<"Yes\n" #define no cout<<"No\n" #define yesno(a) cout<<(a?"Yes\n":"No\n") #define yesnoout(a, b) cout<<(a?"Yes\n":"No")<<(a?b:"")<<"\n" #endif using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair; using pll = pair; template using pq = priority_queue; template using pqg = priority_queue, greater>; template using vec = vector; template using vv = vector>; template using vvv = vector>; const int DX[] = {1, -1, 0, 0}; const int DY[] = {0, 0, 1, -1}; const pair DXY[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; const ll MOD = 998244353ll; // const ll MOD = 1000000007ll; void solve(); signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); unsigned T = 1; cin >> T; cout << fixed << setprecision(20); while (T--) solve(); return 0; } void solve(){ int N; cin >> N; vector A(5*N); for (int& x : A) cin >> x; bool ok = true; rep(i, N){ auto b = vector(A.begin()+5*i, A.begin()+5*i+5); if (!(b[0] == b[2] && b[1] == b[3] && b[3] == b[4] && b[0] != b[1])){ ok = false; } } yesno(ok); }