import java.util.*;
public class Main
{
	public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int T= s.nextInt();
        while(T-->0){
            int n= s.nextInt();
            Map<Integer, ArrayList<Integer>> m= new HashMap<>();
            int[] h= new int[n];
            for(int i=0;i<n;i++){
                h[i]=s.nextInt();
                if(m.containsKey(h[i])){
                    m.get(h[i]).add(i);
                }else{
                    m.put(h[i],new ArrayList<Integer>());
                }
            }
            Iterator hmi= m.entrySet().iterator();
            int min=n-1;
            boolean changed=false;
            while(hmi.hasNext()){
                Map.Entry mapElement = (Map.Entry)hmi.next(); 
                ArrayList<Integer> j=(ArrayList<Integer>)mapElement.getValue();
                for(int i=1;i<j.size() && j.size()!=1;i++){
                    if(min>j.get(i)-j.get(i-1)){
                        min=j.get(i)-j.get(i-1);
                        changed=true;
                    }
                }
            }
            if(min==0|| !changed){
                System.out.println(-1);
            }else
            System.out.println(min+1);
            
        }
	}
}
