import sys from sys import stdin TT = int(stdin.readline()) for loop in range(TT): N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) if A[0] != A[-1]: print ("Yes") else: flag = True f = A[-1] while A and A[-1] == f: del A[-1] A.reverse() while A and A[-1] == f: del A[-1] flag = False for i in range(len(A)-1): if A[i] == A[i+1]: flag = True if flag: print ("Yes") else: print ("No")