t=int(input())
for i in range(t):
    n=int(input())
    a=[int(u) for u in input().split()]
    if(len(a)==1):
        print(-1)
    elif(a==list(set(a))):
        print(-1)
    else:
        b=[int(n) for j in range(n)]
        for j in range(1,n):
            for k in range(j):
                if(a[k]==a[j]):
                    b[j]=j-k+1
        print(min(b))