def solve(n,a): if a[0]!=a[-1]: return True for i in range(n-1): if a[i]==a[i+1]==1-a[0]: return True return False for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if solve(n,a): print('Yes') else: print('No')