import java.util.Arrays;
import java.util.Scanner;
 
 
public class Code {
 
	/**
	 * @param args
	 */
 
	public static void main(String[] args) {
		
		Scanner sc= new Scanner(System.in);
	
	int t=sc.nextInt();
	
	
	
	StringBuilder sb= new StringBuilder();
	
	
	
	while(t-->0)
	{
	int n=sc.nextInt();
	
	
	
	if(n==1){
		int a=sc.nextInt();
	sb.append(-1+"\n");}
	else 
	{
	int[]a= new int[n];
	
	for(int i=0;i<n;i++)
	{
	a[i]=sc.nextInt();	
	}
		int ans=Integer.MAX_VALUE;
	boolean[]used= new boolean[n+1];
	
	for(int i=0;i<n;i++){
		used= new boolean[n+1];
	used[a[i]]=true;
		for(int j=i+1;j<n;j++)
		{
			if(used[a[j]]){
			   ans=Math.min(ans,j-i+1);
			break;
			}
			else 
				used[a[j]]=true;
			
		}
	}
	sb.append(ans+"\n");
	}
		
	
		
	}
		System.out.println(sb.toString());
	}
}