t = int(input())

for _ in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    l2 = l.copy()
    l2.sort()
    # print(l2)
    m2 = l2[-2]
    m1 = l2[-1]

    l3 = list(set(l2[:-2]))
    #print(l3)
    if len(l3) == 1:
        print('YES')
    else:
        print('NO')
