#include using namespace std; #define rep(i,n) for(int i = 0; i < int(n); i++) using ll = long long; using P = pair; bool kadomatsu(ll a, ll b, ll c) { if (a != b && b != c && c != a && (max({a, b, c}) == b || min({a, b, c}) == b)) return true; return false; } bool kadomatsu(vector &a, int x) { for (int i = x - 1; i <= x + 1; i++) { if (1 <= i && i <= (int)a.size() - 2) { if (!kadomatsu(a[i - 1], a[i], a[i + 1])) return false; } } return true; } void solve() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector x; rep(i, n - 2) { if ((a[i] < a[i + 1] && a[i + 1] < a[i + 2]) || (a[i] > a[i + 1] && a[i + 1] > a[i + 2])) { x.push_back(i); x.push_back(i + 1); x.push_back(i + 2); } } x.erase(unique(x.begin(), x.end()), x.end()); if ((int)x.size() > 6) { cout << "No" << endl; return; } rep(i, x.size()) { rep(j, n) { swap(a[x[i]], a[j]); bool ok = true; rep(k, x.size()) { if (!kadomatsu(a, x[k])) ok = false; } if (!kadomatsu(a, j)) ok = false; if (ok) { cout << "Yes" << endl; return; } swap(a[x[i]], a[j]); } } cout << "No" << endl; } int main() { int t; cin >> t; while (t--) { solve(); } return 0; }