import java.io.*;
import java.util.*;
 
 
 
 
public class ds {
 
 
  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();
    int arr[]=new int[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextInt();

    }
    if(n<2){
      sb.append(-1+"\n");
      continue;
    }
    int min=Integer.MAX_VALUE;
    HashSet<Integer> hs=new HashSet<Integer>();
    
    int size=0;
       for(int i=0;i<n;i++){
       // System.out.print("arr: "+arr[i]);
                    hs.add(arr[i]);
                    size=1;

        for(int j=i+1;j<n;j++){
          hs.add(arr[j]);
            int sz=hs.size();
            if(sz==size){
                if(sz+1<min){
                  min=sz+1;
                  
                }
                
                hs.clear();
                break;

            }else{
              size++;
            }
        }
          

       }
       sb.append(min+"\n");
   }
   System.out.println(sb.toString());

  
  }
 
 
}