for t in range(int(input())):
    n=int(input())
    li=list(map(int,input().split()))
    dic={}
    j=0
    if(n==1):
        print(-1)
        continue
    
    ans=100000000
    for i in li:
        if(i not in dic):
            dic[i]=j
        else:
            if(j-dic[i]>=1):
                if(j-dic[i]<ans):
                    ans=j-dic[i]
                    dic[i]=j
                
        
        j=j+1
    print(ans+1)