x = int(input())
for i in range(x):
    a = int(input())
    l = list(map(int, input().split()))
    mass = []
    for i2 in range(a):
        mass += [[l[i2], i2]]
    mass.sort()
    res = 10000000
    for i3 in range(1, a):
        if mass[i3][0] == mass[i3 - 1][0]:
            res = min(res, mass[i3][1] - mass[i3 - 1][1])
    if res == 10000000:
        print(-1)
    else:
        print(res + 1)