import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 md = 10**9+7 # md = 998244353 def iskado(abc): a, b, c = abc if a == b or b == c or c == a: return False if a < b < c or a > b > c: return False return True def solve(): def ok(i, j, lr0): res = True aa[i], aa[j] = aa[j], aa[i] s = max(0, min(i-2, lr0[0])) t = min(n-2, max(i+1, lr0[1]-2)) for k in range(s, t): if not iskado(aa[k:k+3]): res = False break aa[i], aa[j] = aa[j], aa[i] return res n = II() aa = LI() lr = [] l = r = -1 for i in range(n-2): if iskado(aa[i:i+3]): if l != -1 and i >= r: lr.append((l, r)) l = r = -1 else: if l == -1: l, r = i, i+3 else: r = i+3 if r-l == 11: return False if l != -1: lr.append((l, r)) # print(lr) if len(lr) > 2: return False if len(lr) == 2: for l, r in lr: if r-l > 5: return False for i in range(lr[0][0], lr[0][1]): for j in range(lr[1][0], lr[1][1]): if not ok(i, j, lr[0]): continue if not ok(j, i, lr[1]): continue return True if len(lr) == 1: l, r = lr[0] if r-l > 5: for i in range(lr[0][0], lr[0][1]): for j in range(lr[0][0], i): if not ok(i, j, lr[0]): continue if not ok(j, i, lr[0]): continue return True else: for i in range(lr[0][0], lr[0][1]): for j in range(n): if i == j: continue if not ok(i, j, lr[0]): continue if not ok(j, i, lr[0]): continue return True return False for _ in range(II()): print("Yes" if solve() else "No")