for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = [A[0]] for i in range(1, n): if A[i] == A[i - 1]: continue B.append(A[i]) if B[0] == 1: if len(B) % 2 == 0: print("Yes") else: seq_0 = False cnt = 0 for i in range(n): if A[i] == 1: cnt = 0 else: cnt += 1 if cnt > 1: seq_0 = True break if seq_0: print("Yes") else: print("No") else: if len(B) % 2 == 0: print("Yes") else: seq_1 = False cnt = 0 for i in range(n): if A[i] == 0: cnt = 0 else: cnt += 1 if cnt > 1: seq_1 = True break if seq_1: print("Yes") else: print("No")