import java.util.Scanner;

public class DomSubArray {

    static int proc(int length, int []arr, int []count, int []last){
        int res=-1;
        if (length>1){
            for (int i=0; i<length; i++){
                if (count[arr[i]]>1){
                    if (res==-1) res=Math.max(res,i-last[arr[i]]+1);
                    else res=Math.min(res,i-last[arr[i]]+1);
                    last[arr[i]]=i;
                }
            }
        }
        return res;
    }

    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        int testNum = input.nextInt();
        int length;
        for (int i=0; i<testNum; i++){
            length = input.nextInt();
            int []arr= new int[length];
            int []count=new int[200005];
            int []last=new int[200005];
            for (int j=0; j<length; j++) {
                arr[j]=input.nextInt();
                count[arr[j]]++;
                last[arr[j]]=j;
            }
            System.out.println(proc(length,arr,count,last));
        }
    }

}
