def solve(N,A): last=A[0] lis=[] streak=0 for i in range(N): if last!=A[i]: lis.append(streak) streak=1 last=A[i] else: streak+=1 lis.append(streak) if A.count(1)==0 or A.count(0)==0: return False if len(lis)%2==1 and lis.count(1)==len(lis): return False return True T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) if solve(N,A): print('Yes') else: print('No')