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