for _ in range(int(input())):
	n = int(input())
	a = list(map(int , input().split()))

	el = {}
	for i in range(n):
		if a[i] in el:
			el[a[i]].append(i)
		else:
			el[a[i]] = [i]


	md = 99999999999999
	for i in el:
		for j in range(1,len(el[i])):
			md =  min(md , 1 + el[i][j] - el[i][j-1])


	if md != 99999999999999:
		print(md)
	else:
		print(-1)