import sys def is_kadomatsu(a, b, c): if a != b != c and a != c and (a < b > c or a > b < c): return True else: return False input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) d = [0] * (n - 2) for i in range(n - 2): if not is_kadomatsu(a[i], a[i + 1], a[i + 2]): d[i] = 1 s = sum(d) for i in range(n - 1): l = max(0, i - 2) r = min(n - 2, i + 2) cnt = 0 for j in range(l, r): cnt += d[j] if cnt != s: continue flg = True a[i], a[i + 1] = a[i + 1], a[i] for j in range(l, r): flg &= is_kadomatsu(a[j], a[j + 1], a[j + 2]) a[i], a[i + 1] = a[i + 1], a[i] if flg: print('Yes') break else: print('No')