import java.util.*;
import java.io.*;
 
 public class HelloWorld{
 
     public static void main(String []args){
     
     
     Scanner sc = new Scanner(System.in);
     int t = sc.nextInt();
     
     while(t --> 0){
      int n = sc.nextInt();
       int []ar = new int[n+1];
       
      for(int i = 1; i <= n; i++){
          ar[i] = sc.nextInt();
      }
      int []app = new int[200000+1];
      
      int distance = Integer.MAX_VALUE;
      if(n == 1){
          System.out.println(-1);
      }else{
      for(int i = 1; i <= n; i++){
            if(app[ar[i]] == 0){
                app[ar[i]] = i;
            }else{
                int temp = i-app[ar[i]]+1;
                distance = Math.min(temp,distance);
                app[ar[i]] = i;
            }
      }
      if(distance != Integer.MAX_VALUE){
      System.out.println(distance);
      }else{
          System.out.println(-1);
      }
     }
     }
 }
 }
      
          
          