t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int,input().strip().split()))[:n]
    v = []
    x = {}
    dist = 0
    if n == 1:
        print(-1)
        continue
    for j, m in enumerate(a):
        if m not in v:
            v.append(m)
            x[m] = j
        else:
            temp = j - x[m]
            x[m] = j
            if dist == 0 or dist > temp:
                dist = temp
    print(dist+1)