for i in range(int(input())):
	n = int(input())
	l = list(map(int,input().split()))
	d,c,g = {},-1,[]
	for j in range(n):
			if l[j] in d:
				g.append(j-d[l[j]])
				d[l[j]] = j
			else:
				d[l[j]] = j
	if len(g)==0:print(-1)
	else: print(min(g)+1)