for __ in range(int(input())):
    n=int(input())
    x = list(map(int,input().split()))
    d={}
    ll=[]
    for i in range(len(x)):
        try:
            ind=d[x[i]]
            ll.append(i-ind)
            d[x[i]]=i
        except:
            d[x[i]]=i
    if(len(ll)==0):
        print("-1")
    else:
        print(min(ll)+1)








    
    