#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); auto isKadomatsu = [&] (int x, int y, int z) -> bool { if (y > x) { return y > z; } if (y < x) { return y < z; } return false; }; auto isKadomatsuArray = [&] (const vector& v) -> bool{ for (int i = 1; i + 1 < (int) v.size(); i++) { if (!isKadomatsu(v[i - 1], v[i], v[i + 1])) return false; } return true; }; auto solve = [&] () -> string { int n; cin >> n; vector a(n); for (auto& x : a) cin >> x; int center1 = -1; for (int i = 1; i < n - 1; i++) { if (!isKadomatsu(a[i - 1], a[i], a[i + 1])) center1 = i; } int center2 = -1; for (int i = 1; i < n - 1; i++) { if (abs(i - center1) > 2 && !isKadomatsu(a[i - 1], a[i], a[i + 1])) center2 = i; } vector candi; if (center1 >= 1) { for (int i = center1 - 1; i <= center1 + 1; i++) candi.emplace_back(i); } if (center2 >= 1) { for (int i = center2 - 1; i <= center2 + 1; i++) candi.emplace_back(i); } for (auto& x : candi) for (auto& y : candi) { vector v = a; swap(v[x], v[y]); if (isKadomatsuArray(v)) return "Yes"; } return "No"; }; int t; cin >> t; while (t--) cout << solve() << '\n'; return 0; }