import sys from sys import stdin TT = int(stdin.readline()) for loop in range(TT): N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) if A[0] == 1: for i in range(N): A[i] ^= 1 if A[-1] == 1: print ("Yes") else: flag = False for i in range(len(A)-1): if A[i] == A[i+1] == 1: flag = True if sum(A) >= 4: flag = True if flag: print ("Yes") else: print ("No")