import sys def is_valid_triplet(a, b, c): if a == b or b == c or a == c: return False return (b > a and b > c) or (b < a and b < c) def main(): input = sys.stdin.read().split() ptr = 0 T = int(input[ptr]) ptr += 1 for _ in range(T): N = int(input[ptr]) ptr +=1 A = list(map(int, input[ptr:ptr+N])) ptr += N bad = [] for i in range(N-2): a, b, c = A[i], A[i+1], A[i+2] if not is_valid_triplet(a, b, c): bad.append(i) if not bad: print("Yes") continue candidates = set() for i in bad: for x, y in [(i, i+1), (i, i+2), (i+1, i+2)]: if x < N and y < N and A[x] != A[y]: if x > y: x, y = y, x candidates.add((x, y)) found = False for (x, y) in candidates: if x == y: continue if A[x] == A[y]: continue B = A.copy() B[x], B[y] = B[y], B[x] valid = True for i in range(N-2): a, b, c = B[i], B[i+1], B[i+2] if not is_valid_triplet(a, b, c): valid = False break if valid: found = True break print("Yes" if found else "No") if __name__ == "__main__": main()