#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 n = a.size(); rep(i, n - 2) { if (!kadomatsu(a[i], a[i + 1], a[i + 2])) { 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(a[i]); x.push_back(a[i + 1]); x.push_back(a[i + 2]); } } if ((int)x.size() > 20) { cout << "No" << endl; return; } rep(i, x.size()) { rep(j, x.size()) { swap(a[i], a[j]); if (kadomatsu(a)) { cout << "Yes" << endl; return; } swap(a[i], a[j]); } } cout << "No" << endl; } int main() { int t; cin >> t; while (t--) { solve(); } return 0; }