### Dominated Subarray ###
### https://codeforces.com/contest/1257/problem/C ###
s = int(input())
out = []
for i in range(s):
    kq =[]
    n = int(input())
    arr = [int(c) for c in input().split()]
    if n == 1:
        out.append(-1)
    elif n > 1:
        j = 0
        while j < n:
            if arr.count(arr[j]) > 1 and arr[j] != -1:
                x = j
                check = arr[x]
            while arr.count(check) > 1:
                arr[x] = -1
                t = arr.index(check)
                kq.append(t-x+1)
                x = t
            j+=1
        out.append(min(kq))
for i in range(s):
    print(out[i])