def solve(): N = int(input()) A = list(map(int, input().split())) ls = [] prev = -1 for i in range(N): if prev != A[i]: ls.append(1) else: ls[-1] += 1 if len(ls) % 2 == 0: print("Yes") return elif len(ls) >= 9: print("Yes") return else: if A[0] == 0: for i in range(len(A) - 1): if A[i] == A[i + 1] == 1: print("Yes") return else: for i in range(len(A) - 1): if A[i] == A[i + 1] == 0: print("Yes") return print("No") return T = int(input()) for _ in range(T): solve()