import java.util.Arrays;
import java.util.Scanner;

public class C {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        for (int t1 = 0; t1 < t; t1++) {

            int n = sc.nextInt();
            int[] b = new int[n + 1];
            Arrays.fill(b, -1);

            int min = -2;

            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();

                if (b[a] != -1) {
                    if (min == -2 || i - b[a] < min) {
                        min = i - b[a];
                    }
                }

                b[a] = i;
            }

            System.out.println(min + 1);
        }
    }
}
