#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); for (int j = 0; j < n; j++) { std::cin >> a.at(j); } // 2となる位置 int index = -1; for (int j = 0; j < n; j++) { if (a.at(j) == 2) { index = j; break; } } if (index == -1) { std::cout << "No" << std::endl; } else { std::vector to(n); for (int j = index; j < index + n; j++) { int k = j % n; if (a.at(k) == 0) to.at(k) = '>'; else if (a.at(k) == 2) to.at(k) = '<'; else to.at(k) = to.at((k - 1 + n) % n); } bool flag = true; for (int j = 0; j < n; j++) { int count = 0; if (to.at((j - 1 + n) % n) == '>') count++; if (to.at(j) == '<') count++; if (a.at(j) != count) { std::cout << "No" << std::endl; flag = false; break; } } if (flag) std::cout << "Yes" << std::endl; } } }