# 実験してみると # 和がNであり、0が常に1つ以上あり、マックスが2である必要ある # さらに2は連続できない、0も連続できない # WA, 010もありえない 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 zeroonezero_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 if A[(i-2)%N]==0 and A[(i-1)%N]==1 and A[(i)%N]==0: zeroonezero_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 zeroonezero_test == True: ans = 'Yes' print(ans)