for _ in range(input()):
    n=input()
    arr=map(int,raw_input().split())
    ans=-1
    prev=[0 for i in range(max(arr)+1)]
    for i in range(n):
        if prev[arr[i]]==0:
            prev[arr[i]]=i+1
        else:
            if ans==-1:
                ans=i+2-prev[arr[i]]
                prev[arr[i]]=i+1
            else:
                ans=min(ans,i+2-prev[arr[i]])
                prev[arr[i]]=i+1
    print ans
        
