for _ in  range(int(input())):
    n = int(input())
    a = [int(i) for i in input().split()]
    dic = {}
    mini = {}
    for i in range(n):
      if a[i] in  dic:
        if a[i] in mini:
          c = min(mini[a[i]],(i - dic[a[i]]))
          mini[a[i]] = c
        else:
          mini[a[i]] = i - dic[a[i]]
      dic[a[i]] = i
    if mini  == {}:
      print(-1)
    else:
      a = min(mini, key=mini.get)
      print(mini[a]+1 if (a != 2 and n != 1) else -1 )
      

 	   		  	  	   	   	 	 	 	 	