#Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math, queue, collections
MOD = 10**9+7
#sys.stdin = open('input.txt', 'r')

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    x = [[] for i in range(n+1)]
    for i in range(n):
        x[a[i]].append(i)
    ans = -1
    
    for i in range(n+1):
        if len(x[i]) < 2:
            continue
        for j in range(1, len(x[i])):
            if ans == -1:
                ans = x[i][j]-x[i][j-1]+1
            else:
                ans = min(ans, x[i][j]-x[i][j-1]+1)
    print(ans)