import math
t=int(input())
for i in range(t):
    mini=200007
    ans=dict()
    n=int(input())
    arr=list(map(int,input().split()))
    for j in range(n):
        if(arr[j] not in ans.keys()):
            ans[arr[j]]=j
        else:
            curr=j-ans[arr[j]]
            if(curr<mini):
                mini=curr
            ans[arr[j]]=j
    if(mini==200007):
        print(-1)
    else:
        print(mini+1)
            
        
        
    