
for t in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    if ( n < 2 ):
        print(-1)
        continue
    
    l = 2
    passou = False
    while True:
        if ( passou or l > n ):
            break
        for i in range(n - l + 1):
            aux = sorted(a[i:i+l], key=lambda x: a[i:i+l].count(x), reverse=True)
            if ( aux.count(aux[0]) > 1 ):
                print(l)
                passou = True
                break
        l += 1
