
for _ in range(int(input())):
    size=int(input())
    vector=list(map(int,input().split()))
    dicio={}
    for i in range(size):
        if(vector[i] not in dicio):
            dicio[vector[i]]=[i]
        else:
            dicio[vector[i]].append(i)

    resp=300000000
    for i in dicio:
        if(len(dicio[i])>=2):
            for j in range(len(dicio[i])-1):
                resp=min(resp, dicio[i][j+1]-dicio[i][j])
    if(resp==300000000):
        print(-1)
    else:
        print(resp+1)



		   	      	  		 	 		  	   	