

import java.util.Scanner;

public class CCC {

	public static void main(String args[]) {
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		for(int q=0;q<t;q++) {
			int n=scan.nextInt();
			int ar[]=new int[n];
			for(int i=0;i<n;i++)
			{
				ar[i]=scan.nextInt();
			}
			int ans=n+1;
			int freq[]=new int[200007];
			for(int i=0;i<freq.length;i++) {
				freq[i]=-1;
			}
			for(int i=0;i<n;i++) {
				if(freq[ar[i]]!=-1) {
					ans=Math.min(ans,i-freq[ar[i]]+1);
				}
				freq[ar[i]]=i;
			}
			if(ans==n+1) {
				System.out.println("-1");
			}else {
				System.out.println(ans);
			}
		}
	}
}
