t=int(input())
for i in range(t):
   n=int(input())
   a=list(map(int,input().split()))
   m=n
   pos=-1
   if n==1:
      print("-1") 
   else:
      for j in range(1,n):
         if a[j] in a[:j]:
            b=a[:j]
            pos=j-1-b[::-1].index(a[j])
            #pos=a[:j].index(a[j])
            if j-pos<m:
               m=j-pos 
      print(m+1)
         