#include using namespace std; bool is_kadomatsu(int a, int b, int c){ return (b < a && b < c || b > a && b > c) && a != c; } 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 { bool ok = false; int cnt = p.size(); for (int j = 0; j < cnt; j++){ for (int k = j + 1; k < cnt; k++){ swap(A[p[j]], A[p[k]]); bool ok2 = true; for (int l = 0; l < N - 2; l++){ if (!is_kadomatsu(A[l], A[l + 1], A[l + 2])){ ok2 = false; } } if (ok2){ ok = true; } } } if (ok){ cout << "Yes" << endl; } else { cout << "No" << endl; } } } }