#include namespace nono { struct Init {}; void solve([[maybe_unused]] const Init& init) { int n; std::cin >> n; std::vector a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; if (std::ranges::find(a, 0) == a.end()) { std::cout << "No" << std::endl; return; } if (std::ranges::find(a, 2) == a.end()) { std::cout << "No" << std::endl; return; } std::erase_if(a, [](int v) { return v == 1; }); int m = a.size(); for (int i = 0; i < m; i++) { if (a[i] == a[(i + 1) % m]) { std::cout << "No" << std::endl; return; } } std::cout << "Yes" << std::endl; } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; nono::Init init; std::cin >> t; while (t--) nono::solve(init); }