import java.util.*;
public class VC10
{ 
  public static void main(String[] args)
   {
    Scanner s=new Scanner(System.in);
    
    int t=s.nextInt();
    while(t>0)
    {	
	int n=s.nextInt();
	int a[]=new int[n+1];
	int ans=Integer.MAX_VALUE;
	HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
	for(int i=1;i<=n;i++)
	{a[i]=s.nextInt();}
	  for(int i=1;i<=n;i++)
	  {
	    
	    if(h.containsKey(a[i]))
	     {
		ans=Math.min(ans,i-h.get(a[i]));
		h.put(a[i],i);
	     }
	   else
	    {
	     h.put(a[i],i);
	    }
	  
	  }
	if(ans==Integer.MAX_VALUE)
	System.out.println("-1");
	else
	System.out.println(ans+1);
	t--;
    }
	
     
   }
}

