/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            int n= sc.nextInt();
            HashMap<Integer, Integer> map = new HashMap<>();
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int input = sc.nextInt();
                if (map.containsKey(input)) {
                    int val = map.get(input);
                    int ans = i-val;
                    map.put(input, ans);
                    if (min > ans)
                        min = ans;
                } else {
                    map.put(input, i);
                }
            }
           // System.out.println(map);
            if (min == Integer.MAX_VALUE)
                System.out.println(-1);
            else
            System.out.println(min+1);
        }
    }
}

	  	 				 	    	 			 			