q = int(input())
for i in range(q):
    n = int(input())
    arr = list(map(int, input().split()))
    memo = {}
    ret = n
    for index, v in enumerate(arr):
        if memo.get(v) == None:
            memo[v] = index
        else:
            ret = min(index - memo[v] + 1, ret)
            memo[v] = index
    print(ret)
