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 + 4 < i && i < r - 4) { pw.println("No"); return; } } } boolean near = false; if (r - l < 5) { near = true; } int el = Math.min(l + 3, n); for (int i = Math.max(l - 2, 0); i < el; i++) { int sr = i + 1; int er = n; if (!near) { sr = Math.max(r - 2, i + 1); er = Math.min(r + 3, n); } for (int j = sr; j < er; j++) { int t = a[j]; a[j] = a[i]; a[i] = t; boolean flg = true; int e = Math.min(l + 7, n - 2); for (int k = Math.max(l - 4, 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) { int sk = Math.max(j - 2, 0); int ek = Math.min(j + 1, n - 2); if (!near) { sk = Math.max(r - 6, 0); ek = Math.min(r + 5, n - 2); } for (int k = sk; k < ek; 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; } }