from sys import stdin


def input():
    return int(stdin.readline())


def minput():
    return map(int, stdin.readline().split())


def linput():
    return list(map(int, stdin.readline().split()))


for _ in range(input()):
    n = input()
    l = linput()
    d = {}
    min = 20001
    for i in range(n):
        if l[i] not in d:
            d[l[i]] = i
        elif min > i - d[l[i]] + 1:
            min = i - d[l[i]] + 1
            d[l[i]] = i
    if min != 20001:
        print(min)
    else:
        print(-1)