import java.util.Scanner;
import java.io.*;
import java.util.*;
public class domArrayFinal {
	static int N = 200005;
	public static void main(String args[]) throws Exception{
//		Scanner in = new Scanner("4\n" + 
//				"1\n" + 
//				"1\n" + 
//				"6\n" + 
//				"1 2 3 4 5 1\n" + 
//				"9\n" + 
//				"4 1 2 4 5 4 3 2 1\n" + 
//				"4\n" + 
//				"3 3 3 3");
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();in.nextLine();
		for(int i=0;i<T;i++) {
			int n = in.nextInt();in.hasNextLine();
			ArrayList<Integer> fullArr=new ArrayList<Integer>();
			ArrayList<Integer> backUp = new ArrayList<Integer>();
			ArrayList<Integer> toCheck = new ArrayList<Integer>();
			for(int j=0;j<n;j++) {
				fullArr.add(in.nextInt());
			}
			backUp.addAll(fullArr);
			if(i<T-1)
				in.nextLine();
			for(int j=0;j<n;j++) {
				int temp = fullArr.get(j);
				fullArr.remove(j);
				if(fullArr.contains(temp)) {
					if(!toCheck.contains(temp))
						toCheck.add(temp);
				}
				fullArr.clear();
				fullArr.addAll(backUp);
			}
			int first=-1;
			int second=-1;
			int shortestLength=Integer.MAX_VALUE;
			for(Integer num:toCheck) {
				for(int j=0;j<fullArr.size();j++) {
					if(fullArr.get(j)==num) {
						if(first<0) {
							first = j;
						}
						else if(second<0) {
							second = j;
							if(second-first+1<shortestLength)
								shortestLength=second-first+1;
							first = j;
						}else {
							second = j;
							if(second-first+1<shortestLength)
								shortestLength=second-first+1;
							first = j;
						}
					}
				}
				first =-1;
				second = -1;
			}
			if(shortestLength==Integer.MAX_VALUE)
				System.out.println(-1);
			else
				System.out.println(shortestLength);
		}
	}
}
