import sys
n=int(input())
for i in range(n):
    a_l=int(input())
    l=list(map(int,input().split()))
    dicti={}
    mini={}
    for j in range(a_l):
        if l[j] not in dicti:
            dicti[l[j]]=j
            mini[l[j]]=-1
        else:
            temp=j-dicti[l[j]]
            if(mini[l[j]]==-1):
                mini[l[j]]=temp    
            else:
                mini[l[j]]=min(temp,mini[l[j]])
            dicti[l[j]]=j

    m=sys.maxsize
    for a in mini:
        if(mini[a]>0 and mini[a]<m ):
            m=mini[a]

    if(m==sys.maxsize):
        print(-1)
    else:
        print(m+1)
