for _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) if A[0] != A[-1]: print("Yes") else: print("Yes" if any(A[i] == A[i + 1] == 1 - A[0] for i in range(1, N - 2)) else ("Yes" if A.count(1 - A[0]) >= 4 else "No"))