T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) if N==1: print("No") continue if A[0]!=A[-1]: print("Yes") continue flag = 0 for i in range(N-1): if A[i]==A[i+1]==(1-A[0]): flag = 1 break if flag: print("Yes") continue cnt = 0 for i in range(N): if A[i]==(1-A[0]): cnt+=1 if cnt>=4: print("Yes") else: print("No")