#include using namespace std; bool is_kadomatsu(int a, int b, int c){ return (b < a && b < c || b > a && b > c) && a != c; } struct kadomatsu{ int N; vector A; vector B; int sum; kadomatsu(vector A): A(A){ N = A.size(); B = vector(N - 2, false); sum = 0; for (int i = 0; i < N - 2; i++){ if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){ B[i] = true; sum++; } } } void update(int p, int x){ for (int i = p - 2; i <= p; i++){ if (0 <= i && i < N - 2){ if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){ sum--; } } } A[p] = x; for (int i = p - 2; i <= p; i++){ if (0 <= i && i < N - 2){ if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){ sum++; } } } } bool check(){ return sum == N - 2; } }; int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ int N; cin >> N; vector A(N); for (int j = 0; j < N; j++){ cin >> A[j]; } vector B(N, 0); for (int j = 0; j < N - 2; j++){ if (!is_kadomatsu(A[j], A[j + 1], A[j + 2])){ B[j]++; B[j + 1]++; B[j + 2]++; } } vector p; for (int j = 0; j < N; j++){ if (B[j] > 0){ p.push_back(j); } } if (p.size() > 6){ cout << "No" << endl; } else { kadomatsu C(A); int cnt = p.size(); bool ok = false; for (int j = 0; j < cnt; j++){ for (int k = 0; k < N; k++){ if (k != p[j]){ C.update(k, A[p[j]]); C.update(p[j], A[k]); if (C.check()){ ok = true; } C.update(k, A[k]); C.update(p[j], A[p[j]]); } } } if (ok){ cout << "Yes" << endl; } else { cout << "No" << endl; } } } }