def dominated(n,a):
    d={}
    ans=-1
    for i in range(n):
        if d.get(a[i])==None:
            d[a[i]]=i
        else:
            if ans==-1:
                ans=i-d[a[i]]+1
                d[a[i]]=i
            else:
                size=i-d[a[i]]+1
                d[a[i]]=i
                if size<ans:
                    ans=size
    return ans
T=int(input())
for i in range(T):
    n=int(input())
    a=[int(j) for j in input().split()]
    print(dominated(n,a))