ll@T;rep(T){ll@N,@A[N],b=0,t;REP(i,2N){if(b){if(A[i%N]!=1){if(!(b=A[i%N]!=t))break;t=A[i%N];}}else if(A[i%N]!=1)b=1,t=A[i%N];}wt(b?"Yes":"No");}