for _ in range(int(input())):
    n= int(input())
    l=list(map(int,input().split(' ')))
    d=dict()
    for i in range(n):
        if l[i] in d:
            d[l[i]].append(i+1)
        else:
            d[l[i]]=[i+1]
    l1=list(filter(lambda x:len(x)>1,d.values()))
    if len(l1)>0:
        t=9e18
        for i in l1:
            for j in range(1,len(i)):
                if t>(i[j]-i[j-1]+1):
                    t=i[j]-i[j-1]+1
                    if t==2:
                        break
            if t==2:
                break
        print(t)
    else:
        print('-1')
