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