import sys;

def findMinDiff(arr, n): 
  
    # Sort array in non-decreasing order 
    arr = sorted(arr) 
  
    # Initialize difference as infinite 
    diff = 10**20 
    for i in range(n-1): 
        if arr[i+1] - arr[i] < diff: 
            diff = arr[i+1] - arr[i] 
  
    # Return min diff 
    return diff 

iteration = int(input(""))
for i in range(iteration):
    lengthOfArray = (input(""))
    arrayString = sys.stdin.readline() 
    array = list(map(int,arrayString.split()))
    if(len(array) < 2 ):
        print("-1")
    else:       
        #print(array)
        setarray = list(set(array))
        #print(setarray)
        arraymap = []
        for i in setarray:
            number = array.count(i)
            arraymap.append(number)
        
        maxvalocc = max(arraymap) #maximum occurence number
        index = arraymap.index(maxvalocc)
      
        maxoccvalue = setarray[index] #maximum occurence value
            
        duparray = array[:]
        indexlist = []
        i = 0
        for i in range(maxvalocc):
            index = duparray.index(maxoccvalue) + i
            duparray.remove(maxoccvalue)
            indexlist.append(index)
            #print(index)    
            i = i + 1
            
        print(findMinDiff(indexlist,len(indexlist))+1)