def min_dominated_subarray (A):
    '''Находит в массиве А минимальный задоминированный подмассив'''
    count = len(A)
    min_sub = float("inf")
    for i in range(0, count//2):
        for j in range(1, count):
            if A[j] == A[i]:
                if j - i + 1 < min_sub and j - i + 1 > 1:
                    min_sub = j - i + 1
                    i = j
                    j += 1
    if min_sub == float("inf"):
        return -1
    return min_sub

R = []
K = int(input())
for i in range(K):
    L = int(input())
    A = list(input().split())
    A = [int(item) for item in A]
    R.append(min_dominated_subarray(A))

for k in R:
    print(k)