for i in range(int(input())):
    size = int(input())
    lis = list(map(int, input().split()))
    smallest = 10
    for j in range(10):
        indexes = [index for index, element in enumerate(lis) if element == j]
        distances = [indexes[i + 1] - indexes[i] for i in range(len(indexes) - 1)]
        for k in range(len(distances)):
            if distances[k] < smallest:
                smallest = distances[k]
    if smallest < size:
        print(smallest + 1)
    else:
        print(-1)