

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int t = Integer.parseInt(sc.nextLine());

        for(int j = 0; j < t; j++) {
            String[] arr = sc.nextLine().split(" ");

            Map<Integer, Integer> map = new TreeMap<>();
            int min = Integer.MAX_VALUE;

            for (int i = 0; i < arr.length; i++) {
                int a = Integer.parseInt(arr[i]);
                Integer prev = map.get(a);
                map.put(a, i);
                if (prev != null) {
                    int cur = i - prev;
                    if (cur < min) {
                        min = cur;
                    }
                }
            }

            if (min == Integer.MAX_VALUE) {
                min = -2;
            }

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