from collections import Counter
test=int(input())
def takeSecond(elem):
    return elem[1]
for testing in range(test):
    n=int(input())
    t=[int(x) for x in input().split()]
    if n<=1 :
        print(-1)
        continue
    else :
        l=list(set([x for x in t if t.count(x)>1]))
        counted=Counter(t)
        if not len(l):
            print(-1)
            continue
        t=[list(x) for x in list(enumerate(t)) if list(x)[1] in l]
        t.sort(key=takeSecond)
        print(t)
        joker=s=0
        first=True
        while joker<len(l) :
            i=l[joker]
            number=counted[i]
            for i in range(number-1):
                inter=t[s+i+1][0]-t[s+i][0]+1
                if first:
                    mini=inter
                    first=False
                else:
                    if mini>inter :
                        mini=inter
            s+=number
            joker+=1
    print(mini)
