from math import inf
for _ in range(int(input())):
    i = int(input())
    l = list(map(int,input().split()))
    log = {x:-inf for x in set(l)}
    m = inf
    for x in range(i):
        m = min(x-log[l[x]]+1, m)
        log[l[x]] = x
    print(-1 if m == inf else m)