#include //#include #pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector; using mat = vector; ll N,M,H,W,Q,K,A,B; string S; using P = pair; const ll INF = (1LL<<60); template bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template void my_printv(std::vector v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i= N) return true; return a[l] != a[l + 2] && ((a[l] < a[l + 1] && a[l + 1] > a[l + 2]) || (a[l] > a[l + 1] && a[l + 1] < a[l + 2])); } bool judge_plus(vec &a, int p, int q, vec &id){ bool res = true; reps(i, p - 2, p + 1) res &= judge(a, i); reps(i, q - 2, q + 1) res &= judge(a, i); for(int r : id){ reps(i, r - 2, r + 1) res &= judge(a, i); } return res; } void solve(vec &a, vec &id){ for(int i : id) { rep(j, N) { if(i == j) continue; swap(a[i], a[j]); if (judge_plus(a, i, j, id)) { cout << "Yes" << endl; return; } swap(a[i], a[j]); } } cout<<"No"<>Q; rep(_, Q){ cin>>N; vec a(N), can_change_masu(N + 1, 0), id(0); rep(i, N) cin>>a[i]; rep(i, N - 2){ if(!judge(a, i)){ can_change_masu[i] += 1; can_change_masu[i + 3] -= 1; } } rep(i, N) { if(can_change_masu[i] > 0){ id.push_back(i); } can_change_masu[i+1] += can_change_masu[i]; } if(id.size() <= 10){ solve(a, id); }else{ cout<<"No"<