import java.io.*;
import java.util.*;
public class main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int t = Integer.parseInt(br.readLine());
		while(t-- != 0) {
			int N = Integer.parseInt(br.readLine()), curr, Ans = Integer.MAX_VALUE;
			String s[] = br.readLine().split(" ");
			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
			for(int i = 0 ; i < N ; i++) {
				curr = Integer.parseInt(s[i]);
				if(hm.containsKey(curr)) 
					Ans = Math.min(Ans, i - hm.get(curr) + 1);
				hm.put(curr, i);
			}
			pw.println(Ans == Integer.MAX_VALUE ? -1 : Ans);
		}
		pw.flush();
	}
}
