from collections import defaultdict import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) D = defaultdict(int) flag = True for i in range(N): if A[i]==A[(i+1)%N]==0 or A[i]==A[(i+1)%N]==2: flag = False break D[A[i]] += 1 if D[0]==0 or D[2]==0: flag = False if D[1]+D[2]*2!=N: flag = False if flag: print("Yes") else: print("No")