T=int(input())
for t in range(T):
    n=int(input())
    arr=list(map(int,input().split()))
    s=set()
    i=0
    j=0
    ans=10**6
    count=0
    while(j<n):
        s.add(arr[j])
        count+=1
        if(len(s)!=count):
            ans=min(count,ans)
            s.clear()
            count=0
            i=j
        else:
            j+=1
    if(ans==10**6):
        print(-1)
        continue
    print(ans)
            
        
        