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

import static java.lang.Math.*;

public class Solution{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();

        for (int i = 0; i < t; i ++){
            int n = in.nextInt();
            int[] X = new int[n];
            Solution ofProblem = new Solution();
            ofProblem.getAnswer(n, X);
        }
    }
    private void getAnswer(int integer, int[] array){
        int ans = 222222;
        int[] Y = new int[integer+1];
        Arrays.fill(Y, -1);
        for (int i = 0; i < integer; i ++){
            if (Y[array[i]] == -1){
                Y[array[i]] = i;
            }else{
                ans = min(ans, i - Y[array[i]] + 1);
                Y[array[i]] = i;
            }
        }
        if (ans == 222222){
            System.out.println(-1);
        }else{
            System.out.println(ans);
        }
    }
}