for _ in range(int(input())):
    n = int(input())
    l = list(map(int,input().split()))
    m=10**18
    f=0
    for i in range(n-1):
        for j in range(i+1,n):
            if l[i]==l[j]:
                f=1
                x=j-i+1
                break
        if x<m:
            m=x
    if f==1:
        print(m)
    else:
        print(-1)