import sys input = sys.stdin.readline T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) in_deg = [0 for _ in range(N)] flag = True for i in range(N): pre = (i-1)%N nxt = (i+1)%N if A[i]==2: if in_deg[pre]+A[pre]>=2 or in_deg[nxt]+A[nxt]>=2: flag = False break in_deg[pre]+=1 in_deg[nxt]+=1 elif A[i]==1: if in_deg[pre]+A[pre]>=2: if in_deg[nxt]+A[nxt]>=2: flag = False break else: in_deg[nxt]+=1 else: in_deg[pre]+=1 for i in range(N): if A[i]+in_deg[i]!=2: flag = False break if flag: flag = False for i in range(N): if A[i]!=1: flag = True break if flag: print("Yes") else: print("No") else: print("No")