for _ in range(int(input())):
    n = int(input())
    l = list(map(int, input().split()))
    d = {}
    mn = 1e10
    for i in range(n):
        if l[i] in d.keys():
            mn = min(mn, i - d[l[i]])
        d[l[i]] = i
    print(-1 if mn == 1e10 else (mn + 1))



