for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [] for i in a: if i != 1: b.append(i) print("Yes" if b and all(b[i] != b[i + 1] for i in range(len(b) - 1)) else "No")