for i in range(int(input())):
    n = int(input())
    l=list(map(int,input().split()))
    s =set(l)
    mini=n
    d = {}
    if len(s)==n:
        print(-1)
        continue
    for i in range(n):
        try:
            d[l[i]].append(i+1-d[l[i]][-1])
        except:
            d[l[i]] = [i]
    for key,val in d.items():
        if len(val)>1 and mini>min(val[1:]):
            mini = min(val[1:])+1
    print(mini)