import sys from itertools import permutations input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) import random for _ in range(int(input())): N = int(input()) A = li() k = A.count(1) if k < N-k: A = [1-a for a in A] if A[0] == 0 or A[-1] == 0: print("Yes") continue flg = True for i in range(1,N-1): if A[i] == 0: if A[i-1] == 0 or A[i+1] == 0: flg = False print("No" if flg else "Yes")