t = int(input())
for i in range(0,t):
    c = []
    n = int(input())

    for j in range(0,n+10):
        c.append(-1)
    m = input()
    if n == 1:
        print(-1)
        continue
    x = []
    x = [int(xx) for xx in m.split()]
    a = 0
    min = n+10
    for xx in x:
        if (c[xx]==-1):
            c[xx] = a
        else:
            dif = a - c[xx] + 1
            c[xx] = a
            if dif<min:
                min=dif
        a = a+1
    print(min)

