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