//SHIVAM GARG
import java.util.*;
import java.lang.*;
import java.io.*;

public class Test
{
    public static void main (String[] args) throws java.lang.Exception {
        FastReader reader = new FastReader();
        int tests = reader.nextInt();
        HashMap<Integer, Integer>  tracker;
        int n, ans, temp;
        boolean flag;
        int[] arr;
        for(int test=0;test<tests;test++){
            n= reader.nextInt();
            arr = new int[n];
            flag =false;
            ans = Integer.MAX_VALUE;
            tracker= new HashMap<Integer, Integer>();
            for(int i=0;i<n;i++){
                arr[i] = reader.nextInt();
                if(tracker.get(arr[i])  != null ){
                    flag = true;
                    temp  = i -  tracker.get(arr[i]) +1 ;
                    tracker.put(arr[i], i);
                    if(ans >  temp ){
                        ans = temp;
                    }
                }
                tracker.put(arr[i], i);
            }
            if(flag){
                System.out.println(ans);    
            }else{
                System.out.println(-1);    
            }
            
    }
}

	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        {  br = new BufferedReader(new InputStreamReader(System.in));  } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) { 
                try{ 
                    st = new StringTokenizer(br.readLine()); 
                }catch (IOException  e) { 
                    e.printStackTrace(); 
                    
                }
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { return Integer.parseInt(next());  } 
  
        long nextLong() 
        {  return Long.parseLong(next());  } 
  
        double nextDouble() 
        {  return Double.parseDouble(next());  } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	
	
}
