c = 200001 
t = int(input())
while t:
    _ = int(input())
    a = [-1]*c
    ans = c 
    for i, e in enumerate(map(int, input().split())):
        if a[e] == -1:
            a[e] = i
        else:
            ans = min(ans, i - a[e] + 1)
            a[e] = i
    
    print([ans, -1][ans == c])           
    t -= 1