import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Vector;

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 arr[] = new int[n];
            int min = Integer.MAX_VALUE;
            HashMap<Integer, Integer>  hm = new HashMap<>();
            for(int i =0; i <n; i++) {
                arr[i] = sc.nextInt();
                if(hm.containsKey(arr[i])) {
                    if(i - hm.get(arr[i]) + 1 < min) min = i -hm.get(arr[i])+1;
                }
                hm.put(arr[i], i);
            }
            if(min == Integer.MAX_VALUE) {
                min = -1;
            }
            System.out.println(min);
        }
    }

}