from sys import stdin
for _ in range(int(stdin.readline())):
    n = int(stdin.readline())
    arr = list(map(int,stdin.readline().split()))
    d = {}
    for i in range(n):
        if arr[i] in d:
            d[arr[i]].append(i)
        else:
            d[arr[i]] = [i]
    ans = list(filter(lambda x: len(x)>=2, d.values()))
    if len(ans)==0:
        print(-1)
    else:
        
        m = 10000000
        for ele in ans:
            for i in range(len(ele)-1):
                m = min(ele[i+1] - ele[i], m)
        print(m+1)
