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>(n);
			ArrayList<Integer> backUp = new ArrayList<Integer>(n);
			ArrayList<Integer> toCheck = new ArrayList<Integer>(n);
			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);
			}
			toCheck.trimToSize();
			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);
		}
	}
//	import java.math.*;
//	import java.util.*;
//	public class JavaApplication11 {
//	    public static void main(String[] args) {
//	        Scanner io = new Scanner(System.in);
//	        long q = io.nextInt();
//	        while(q-- != 0) {
//	            int n = io.nextInt();
//	            int[] a = new int[n];
//	            int[] oc = new int [n+1];
//	            boolean[] f = new boolean[n+1];
//	            ArrayList<Integer>[] o = new ArrayList[n+1];
//	            for (int i = 0; i <= n; i++) { 
//	                o[i] = new ArrayList<Integer>(); 
//	            } 
//	            for(int i = 0; i < n; i++) {
//	                a[i] = io.nextInt();
//	                oc[a[i]]++;
//	                if(oc[a[i]] > 0)
//	                    o[a[i]].add(i);
//	            }
//	            for(int i = 0; i < o.length; i++) if(o[i].size()<2) o[i].clear();
//	            int res = Integer.MAX_VALUE;
//	            for(int i = 0; i < o.length; i++) {
//	                if(o[i].size() == 0) continue;
//	                for(int j = 0; j < o[i].size()-1; j++)
//	                    res = Integer.min(res, (o[i].get(j+1) - o[i].get(j) + 1));
//	            }
//	            System.out.println(res == Integer.MAX_VALUE ? -1 : res);
//	        }
//	    }
//	}
}
