// CodeForces Round #1257 B compet

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class DominatedSubarray {

	final static int MAXA = 200100;
	int n;
	int []a;
	int ans;

	private void readData(BufferedReader bin) throws IOException {
		String s = bin.readLine();
		String []ss = s.split(" ");
		int ng = Integer.parseInt(ss[0]);
		a = new int[MAXA];
		for (int ig=0; ig<ng; ig++) {
			s = bin.readLine();
			ss = s.split(" ");
			n = Integer.parseInt(ss[0]);
			s = bin.readLine();
			ss = s.split(" ");
			for (int i=0; i<n; i++) {
				a[i] = Integer.parseInt(ss[i]);
			}
			calculate();
			printRes();
		}		
	}

	void printRes() {
		System.out.println(ans);
	}	

	/** calculate ans */
	private void calculate() {
		int minSame = MAXA;
		int []lastOcc = new int[MAXA];
		Arrays.fill(lastOcc, -1);
		for (int i=0; i<n; i++) {
			int aa = a[i];
			if (lastOcc[aa] != -1) {
				int d = i - lastOcc[aa];
				if (d < minSame) {
					minSame = d+1;
				}				
			}
			lastOcc[aa] = i;
		}
		ans = (minSame < MAXA ? minSame : -1);		
	}

	public static void main(String[] args) throws IOException {
		// BufferedReader bin = new BufferedReader(new FileReader("cactus.in"));
		BufferedReader bin = new BufferedReader(
				new InputStreamReader(System.in));
		DominatedSubarray l = new DominatedSubarray();
		l.readData(bin);
		//l.calculate();
		//l.printRes();
	}
}
