T = int(input()) def check(s): return len(s) == 5 and s[0] == s[2] and s[1] == s[3] == s[4] and s[0] != s[1] for _ in range(T): N = int(input()) A = list(map(int,input().split())) print("Yes" if all(check(A[i:i+5]) for i in range(0,5*N,5)) else "No")