import java.util.*;
public class cfedu76div2C {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        for(int p=1;p<=t;p++)
        {int n=sc.nextInt(),min=Integer.MAX_VALUE;
        int arr[]=new int[n];int c=0;
        int pos[]=new int[n+1];
        for(int i=0;i<n;i++)
        {arr[i]=sc.nextInt();
        if(pos[arr[i]]==0)
        {pos[arr[i]]=i+1;
        c=Integer.MAX_VALUE;}
        else
        {c=i+1-pos[arr[i]];
        pos[arr[i]]=i+1;}
        if(c<min)
        min=c;}
        if(min!=Integer.MAX_VALUE)
        System.out.println(min+1);
        else
        System.out.println(-1);
        }

        sc.close();}}