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 + 2]; 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.first(); int r = set.last(); if (r - l >= 3) { pw.println("No"); return; } for (int i = l; i < r + 2; i++) { for (int j = i + 1; j < r + 3; j++) { int t = a[j]; a[j] = a[i]; a[i] = t; boolean flg = true; for (int k = Math.max(i - 2, 0); k <= r; 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) { 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; } }