T = int(input())
for t in range(T):
    ans = 1000000000
    n = int(input())
    a = list(zip(list(map(int, input().split())), list(range(n))))
    a.sort()
    for i in range(1, n):
        if a[i][0] == a[i-1][0]:
            ans = min(a[i][1] - a[i-1][1], ans)
    if ans == 1000000000:
        print("-1")
    else:
        print(ans+1)