#include using namespace std; void solve() { int N; cin >> N; std::vector A(N); for (auto& a : A) { cin >> a; } bool zr = false, tw = false; for (int i = 0; i < N; i ++) { zr = zr || (A[i] == 0); tw = tw || (A[i] == 2); } if (!(zr && tw)) { puts("No"); return; } for (int i = 0; i < N; i ++) { A.push_back(A[i]); } int pre = 0; for (auto a : A) { if ((a - 1) * pre > 0) { puts("No"); return ; } if (a - 1) { pre = a - 1; } } puts("Yes"); } int main() { int T; cin >> T; while (T--) { solve(); } }