T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) cnt = 0 for a in A: if a==1: cnt+=1 if cnt*2==N: print("Yes") continue if cnt>N-cnt: sa = cnt - (N-cnt) chk = 1 else: sa = (N-cnt) - cnt chk =0 tmp = 0 for i in range(N-1): if A[i]==A[i+1]==chk: tmp += 1 if tmp==sa: break if tmp==sa: print("Yes") else: print("No")