import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class code {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        int[] ans = new int[t];
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            List<Integer> arr = new ArrayList<>();
            int minlength = n+1;
            for (int j = 0; j < n; j++) {
                int x = in.nextInt();
                int ind = arr.indexOf(x);
                if(ind!=-1&&j-ind<minlength) {
                    minlength=j-ind;
                }
                arr.add(x);
            }
            ans[i]=minlength==n+1?-1:minlength+1;
        }
        for(int i:ans){
            System.out.println(i);
        }
    }
}
