t=int(input())
for tst in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    mini=10000000
    if len(l)<2:
        print(-1)
    else:
        for i in range(n):
            j=i+1
            ui=i
            while j<n:
                if l[i]==l[j]:
                    mini=min(mini,j-ui)
                    ui=j
                j+=1
        print(mini+1)







