for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = list(set(a))
	count = 0
	for i in p:
		if a.count(i) > 1:
			count += 1
			prev_diff = n
			k = a.index(i)
			for j in range(k + 1, n):
				if a[j] == i:
					new_diff = j - k
					k = j
					diff = min(new_diff, prev_diff)
					prev_diff = new_diff
		else :
			continue
	if count == 0:
		diff = -2
	print(diff + 1)
