
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        for(int i = 0; i < num; i++)
        {
        	int num1 = sc.nextInt();
        	if(num1 == 1)
        	{
        		System.out.println("-1");
        		continue;
        	}
        	int[] numLine = new int[num1];
        	for(int j = 0; j < num1; j++)
        	{
        		numLine[j] = sc.nextInt();
        	}
        	int length = 200000;
        	for(int j = 0; j < num1; j++)
        	{
        		for(int k = j + 1; k < num1; k++)
        		{
        			if(numLine[j] == numLine[k])
        			{
        				if(k - j + 1 < length)
        				{
        					length = k - j + 1;
        				}
        				break;
        			}
        		}
        	}
        	if(length == 200000)
        	{
        		System.out.println("-1");
        		continue;
        	}
        	System.out.println(length);
        }
    }
}