#include #include int main() { int t; std::cin >> t; for (int i = 0; i < t; i++) { int n; std::cin >> n; std::vector a(n + 2); for (int j = 1; j <= n; j++) { std::cin >> a.at(j); } a.at(0) = a.at(n); a.at(n + 1) = a.at(1); int total = 0; bool flag = true, is_zero = false, is_two = false; for (int j = 1; j <= n; j++) { if (a.at(j) == 0) { is_zero = true; if (a.at(j - 1) == 0 || a.at(j + 1) == 0) { std::cout << "No" << std::endl; flag = false; break; } } else if (a.at(j) == 2) { is_two = true; if (a.at(j - 1) == 2 || a.at(j + 1) == 2) { std::cout << "No" << std::endl; flag = false; break; } } total += a.at(j); } if (flag) { if (is_zero && is_two && total == n) { std::cout << "Yes" << std::endl; } else { std::cout << "No" << std::endl; } } } }