for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    mark = [-1]*(200001)
    dist = 200001
    for i in range(n):
        if mark[a[i]] == -1:
            mark[a[i]] = i
        else:
            temp = i - mark[a[i]]
            if temp >= 1:
                dist = min(temp, dist)
            mark[a[i]] = i
    if dist == 200001:
        print("-1")
        continue
    print(dist+1)
