# 実験してみると # 和がNであり、0が常に1つ以上あり、マックスが2である必要ある # さらに2は連続できない、0も連続できない # WA, 010もありえない、011110のようなのもありえない T = int(input()) for t in range(T): N = int(input()) A = list(map(int, input().split())) zero_test = False max_test = True sum_test = False if sum(A)==N: sum_test = True for a in A: if a == 0: zero_test = True if a > 2: max_test = False zero_consec_test = True two_consec_test = True for i in range(N): if A[(i-1)%N]==2 and A[i]==2: two_consec_test = False if A[(i-1)%N]==0 and A[i]==0: zero_consec_test = False zeroone_check = False zeroone_test = True for i in range(N): if zeroone_check == False: if A[(i-1)%N]==0 and A[i]==1: zeroone_check = True else: if A[i] == 2: zeroone_check = False elif A[i] == 1: pass elif A[i] == 0: zeroone_test = False ans = 'No' if sum_test == True and zero_test == True and max_test == True: if zero_consec_test == True and two_consec_test == True and zeroone_test == True: ans = 'Yes' print(ans) #print('zeroone_test', zeroone_test)