T = int(input()) for _ in range(T): N = int(input()) A = list(map(int,input().split())) f = True f &= sum(A) == N for i in range(N): if A[i] == 0 and A[(i + 1) % N] == 0: f = False if A[i] == 2 and A[(i + 1) % N] == 2: f = False f0 = False f2 = False for i in range(N): if A[i] == 0: f0 = True if A[i] == 2: f2 = True if f & f0 & f2 : print("Yes") else: print("No")