for j in range(int(input())):
    p=int(input())
    def maxDistance(arr, n):
    	mp = {}
    	maxDict = 0
    	k=[]
    	for i in range(n): 
    		if arr[i] not in mp.keys(): 
    			mp[arr[i]] = i 
    		else: 
    			maxDict = max(maxDict, i-mp[arr[i]])
    			k.append(i-mp[arr[i]]+1)
    			mp[arr[i]] = i 
    	if len(k)==0:
    	    k.append(-1)
    	return min(k)
    if __name__=='__main__': 
    	arr =list(map(int,input().split()))
    	n =p
    	print (maxDistance(arr, n))