import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.TreeSet; public class Main { static BufferedReader br; static PrintWriter pw; public static void main(String[] args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); pw = new PrintWriter(System.out); for (int i = 0; i < t; i++) { solve(); } br.close(); pw.flush(); } static void solve() throws Exception { int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } TreeSet set = new TreeSet<>(); for (int i = 0; i < n - 2; i++) { int[] b = new int[3]; for (int j = 0; j < 3; j++) { b[j] = a[i + j]; } if (!check(b)) { set.add(i); } } int l = set.pollFirst(); int r = l; if (!set.isEmpty()) { r = set.pollLast(); } if (!set.isEmpty()) { for (int i : set) { if (l + 2 < i && i < r - 2) { pw.println("No"); return; } } } int el = Math.min(l + 3, n); for (int i = Math.max(l - 2, 0); i < el; i++) { int er = Math.min(r + 3, n); for (int j = Math.max(r - 2, l + 1); j < er; j++) { int t = a[j]; a[j] = a[i]; a[i] = t; boolean flg = true; int e = Math.min(i + 3, n - 2); for (int k = Math.max(l - 2, 0); k < e; k++) { int[] b = new int[3]; for (int k2 = 0; k2 < 3; k2++) { b[k2] = a[k + k2]; } if (!check(b)) { flg = false; break; } } if (flg) { e = Math.min(r + 3, n - 2); for (int k = Math.max(j - 2, 0); k < e; k++) { int[] b = new int[3]; for (int k2 = 0; k2 < 3; k2++) { b[k2] = a[k + k2]; } if (!check(b)) { flg = false; break; } } if (flg) { throw new Exception(); // pw.println("Yes"); // return; } } a[i] = a[j]; a[j] = t; } } pw.println("No"); } static boolean check(int[] a) { if (a[0] != a[2]) { if (a[0] < a[1] && a[1] > a[2]) return true; if (a[0] > a[1] && a[1] < a[2]) return true; } return false; } }