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