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

public class ECR76C {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            int[] a = new int[n];
            for (int j = 0; j < n; j++) {
                a[j] = scanner.nextInt();
            }
            int ans = Integer.MAX_VALUE;
            if (n == 1) {
                ans = -1;
            } else {
                int[] f = new int[200001];
                Arrays.fill(f, -1);
                for (int j = 0; j < n; j++) {
                    if (f[a[j]] > -1) {
                        int l = j - f[a[j]] + 1;
                        ans = Math.min(ans, l);
                        if (ans == 2) break;
                    }
                    f[a[j]] = j;
                }
            }
            System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
        }
    }
}
