import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		 BufferedReader br = new BufferedReader(new
		 InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("in.txt")));
		StreamTokenizer in = new StreamTokenizer(br);
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		in.nextToken();
		int t = (int) in.nval;
		int[] arr = new int[200005];
		int[] idx = new int[200005];
		int n, ans, max, i, tmp, val;
		boolean flag;
		while (--t >= 0)
		{
			in.nextToken();
			n = (int) in.nval;
			Arrays.fill(idx, -1);
			val = -1;
			for (i = 0; i < n; i++)
			{
				in.nextToken();
				if (val == 2)
					continue;
				tmp = (int) in.nval;
				if (idx[tmp] == -1)
					idx[tmp] = i;
				else
				{
					if (val == -1)
						val = i - idx[tmp] + 1;
					else if (val > i - idx[tmp] + 1)
						val = i - idx[tmp] + 1;
					idx[tmp] = i;
				}
			}
			pr.println(val);
		}
		pr.flush();
	}
}