for _ in range(input()):
	n = input()
	l = map(int, raw_input().split())
	dic = {}
	for i in range(n):
		if l[i] in dic:
			dic[l[i]].append(i)
		else:
			dic[l[i]] = [i]
	ans = n + 1
	for i in dic:
		if len(dic[i]) > 1:
			for j in range(len(dic[i])-1):
				ans = min(ans, dic[i][j+1] - dic[i][j] + 1)
	if ans == n + 1:
		print -1
	else:
		print ans