for _ in range(int(input())):
	n=int(input())
	l=list(map(int,input().split()))
	ans=[]
	d={}
	for i in range(n):
		if l[i] in d:
			ans.append(i-d[l[i]]+1)
		d[l[i]]=i
	if ans!=[]:
		print(min(ans))
	else:
		print(-1)