import math
#n=int(input())
for _ in range(int(input())):
    n=int(input())
    a={}
    x=[int(n) for n in input().split()]
    m=1000000000
    for i in range(len(x)):
        if x[i] not in a:
            a[x[i]]=[]
        a[x[i]].append(i)
    if len(a)==n:
        print(-1)
        continue 
    for i in a:
        l=len(a[i])
        #print(a[i][1])
        if l>1:
            for j in range(1,len(a[i])):
                m=min(abs(a[i][j]-a[i][j-1])+1,m)
    print(m)
            
        