import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public final class SolutionC{

    private static Map<Integer, List<Integer>> map = new HashMap<>();

    private static void parseToMap(int n, int pos){
        if(map.containsKey(n)){
            List<Integer> l = map.get(n);
            if(l.get(2) < (pos - l.get(1))){
                l.set(0, l.get(1));
                l.set(1, pos);
                l.set(2, pos - l.get(0));
            }
        } else {
            map.put(n, Arrays.asList(-1, pos, -1));
        }
    }

    private static int getSmallestLength(){
        int temp = map.entrySet()
                        .stream()
                        .mapToInt(e -> e.getValue().get(2))
                        .min().orElse(-1);
        return temp == -1 ? -1 : temp + 1;
    }

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();

        List<Integer> result = new ArrayList<>();
        for(int i = 0; i < t; i++){
            long len = scanner.nextInt();
            for(int j = 0; j < len; j++){
                parseToMap(scanner.nextInt(), j);
            }
            result.add(getSmallestLength());
            map.clear();
        }

        for(int i = 0; i < t; i++){
            System.out.println(result.get(i));
        }

        scanner.close();
    }
}