using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new bool[t]; for (var u = 0; u < t; ++u) { var n = NN; var a = NList; ans[u] = Kado(n, a); } WriteLine(string.Join("\n", ans.Select(f => f ? "Yes" : "No"))); } static bool Kado(int n, int[] a) { var nglist = new List(); for (var i = 0; i + 2 < n; ++i) if (!IsKadomatsu(a[i..(i + 3)])) nglist.Add(i); if (nglist.Count > 6) return false; var chlist = new List(); foreach (var ni in nglist) for (var i = 0; i < 3; ++i) if (ni + i < n) chlist.Add(ni + i); chlist = chlist.Distinct().ToList(); WriteLine(string.Join(" ", chlist)); for (var i = 0; i < chlist.Count; ++i) for (var j = i + 1; j < chlist.Count; ++j) { (a[chlist[i]], a[chlist[j]]) = (a[chlist[j]], a[chlist[i]]); var flg = true; for (var p = Math.Max(0, chlist[i] - 2); p <= chlist[i] && p + 2 < n; ++p) { if (!IsKadomatsu(a[p..(p + 3)])) flg = false; } for (var p = Math.Max(0, chlist[j] - 2); p <= chlist[j] && p + 2 < n; ++p) { if (!IsKadomatsu(a[p..(p + 3)])) flg = false; } foreach (var p in chlist) if (p + 2 < n && !IsKadomatsu(a[p..(p + 3)])) flg = false; if (flg) return true; (a[chlist[i]], a[chlist[j]]) = (a[chlist[j]], a[chlist[i]]); } return false; } static bool IsKadomatsu(int[] a) { return a[0] != a[2] && ((a[0] > a[1] && a[1] < a[2]) || (a[0] < a[1] && a[1] > a[2])); } }