t = input()
for _ in xrange(t):
    n = input()
    ans = 999999999999
    m = {}
    l = map(int, raw_input().split())
    if n==1:
        print -1
        continue
    m[l[0]]=0
    for i in xrange(1,n):
        if l[i] in m:
            ans = min(ans,i-m[l[i]]+1)
        m[l[i]] = i
    print ans
