# coding: utf-8 # Your code here! T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) dic={0:0,1:0,2:0} for a in A: dic[a]+=1 n_zero=0 n_one=dic[0] n_two=N-dic[2] B=[] for a in A: if a==0: B.append(n_zero) n_zero+=1 elif a==1: B.append(n_one) n_one+=1 else: B.append(n_two) n_two+=1 C=[] for i in range(N): if B[i]>B[i-1] and B[i]>B[(i+1)%N]: C.append(2) elif B[i]>B[i-1] or B[i]>B[(i+1)%N]: C.append(1) else: C.append(0) if A==C: print("Yes") else: print("No")