test_count = int(input())
for _ in range(test_count):
    n = int(input())
    a = list(map(int, input().split()))
    positions = list()
    for _ in range(n):
        positions.append(list())

    for i in range(len(a)):
        positions[a[i] - 1].append(i)

    ans = -1
    for row in positions:
        for i in range(1, len(row)):
            if ans == -1:
                ans = row[i] - row[i - 1] + 1
            else:
                ans = min(row[i] - row[i - 1] + 1, ans)
    print(ans)