import java.util.Scanner;
import java.util.Arrays;
public class file2{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n,t = sc.nextInt(), arr[];
		int ans;

		while(t>0)
		{
			t--;
			ans = -1;
			n= sc.nextInt();
			arr = new int[n];
			for(int i=0;i<n;i++)
			{
				arr[i] = sc.nextInt();
			}
			int map[] = new int[n+1];
			Arrays.fill(map,-1);
			for(int i=0;i<n;i++)
			{
				int num = arr[i];
				if(map[num]==-1)
					map[num] = i;
				else{
					int currdist = i - map[num] + 1;
					if(currdist < ans || ans == -1)
						ans = currdist;
					map[num] = i;
				}
			}
			System.out.println(ans);

		}
	}
}