#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 998244353; bool is_kadomatsu(ll a, ll b, ll c) { if (a == b || b == c || a == c)return false; if ((a < b && b > c) || (a > b && b < c))return true; else return false; } signed main() { ios::sync_with_stdio(false); cin.tie(0); ll T; cin >> T; for (int _ = 0; _ < T; _++) { ll N; cin >> N; vectorA(N); for (int i = 0; i < N; i++)cin >> A[i]; vectorok(N - 2, true); for (int i = 0; i < N - 2; i++) { if (!is_kadomatsu(A[i], A[i + 1], A[i + 2]))ok[i] = false; } int cnt = 0; for (int i = 0; i < N - 2; i++) { if (!ok[i])cnt++; } for (int i = 0; i < N - 2; i++) { if (!ok[i]) { bool now = false; for (int j = 0; j < 3; j++) { for (int k = 0; k < N; k++) { vectorB = ok; int tmp = cnt; swap(A[i + j], A[k]); for (int l = max(0, i + j - 3); l < min((int)N - 2, i + j + 3); l++) { if (!ok[l] && is_kadomatsu(A[l], A[l + 1], A[l + 2])) { tmp--; ok[l] = true; } else if (ok[l] && !is_kadomatsu(A[l], A[l + 1], A[l + 2])) { tmp++; ok[l] = false; } } for (int l = max(0, k - 3); l < min((int)N - 2, k + 3); l++) { if (!ok[l] && is_kadomatsu(A[l], A[l + 1], A[l + 2])) { tmp--; ok[l] = true; } else if (ok[l] && !is_kadomatsu(A[l], A[l + 1], A[l + 2])) { tmp++; ok[l] = false; } } if (tmp == 0) { now = true; } swap(A[i + j], A[k]); ok = B; } } if (now) { cout << "Yes" << endl; } else { cout << "No" << endl; } break; } } } return 0; }