import java.util.*;
public class Main
{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0) {
        	int n = sc.nextInt();
        	int diff=0, min_diff=Integer.MAX_VALUE;
        	HashMap<Integer, Integer> hs = new HashMap<>();
        	for(int i=0; i<n ; i++) {
        		Integer returned_value = (Integer)hs.put(sc.nextInt(), i);
        		if(returned_value!=null) {
        			diff=i-returned_value;
        			min_diff = Math.min(diff, min_diff);
        		}
        	}
        	if(min_diff==Integer.MAX_VALUE)
        		System.out.println("-1");
        	else
        		System.out.println(min_diff+1);
        }
    }
}