t=int(input())
for _ in range(t):
    p=[]
    vis=[]
    ans=2000000000
    n=int(input())
    l=list(map(int,input().split()))
    for i in range(n-1):
        if l[i+1:].count(l[i])>=1 and l[i] not in vis:
            vis.append(l[i])
            p.append(i)
            for j in range(i+1,n):
                if l[j]==l[i]:
                    p.append(j)
            
            for r in range(len(p)-1):
                if p[r+1]-p[r]+1<ans:
                    ans=p[r+1]-p[r]+1
        p=[]
    if ans==0:
        print(-1)
    else:
        print(ans)