T=int(input())
h=[1]*T
for q in range (0,T):
    n=int(input())
    a=list(map(int,input().split()))
    if n==1:
        h[q] = -1
    else:
        min=n+1
        for i in range (0,n):
            m=a[i]
            a[i] = -1
            if a.count (m)>0: k=a.index(m)-i+1
            if k<min and k!=0: min=k
        if min!=n+1: h[q]=min
        else: h[q]=-1
for q in range (0,T):
    print (h[q])