for _ in range(int(input())):
    n = int(input())
    a = [*map(int,input().split())]
    d = {}
    ans = -1
    for i in range(n):
        if a[i] in d and ans == -1:
            ans = i + 1 - d[a[i]]
        elif a[i] in d and ans != -1:
            ans = min(ans, i + 1 - d[a[i]])
        d[a[i]] = i + 1
    print(ans + 1 if ans != -1 else ans)