import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class A {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static FastReader scn = new FastReader();

    public static void main(String[] args) {
        int t = scn.nextInt();
        while(t-- > 0) run();
    }

    private static void run(){
        int n = scn.nextInt();
        int[] arr = new int[n];

        for(int i = 0; i<n; i++) arr[i] = scn.nextInt();

        HashMap<Integer,Integer> map = new HashMap<>();

        int res = Integer.MAX_VALUE;
        for(int i = 0; i<n; i++){
            int a = arr[i];
            if(map.containsKey(a)){
                int b = map.get(a);
                int temp = i-b+1;
                res = Math.min(res,temp);
            }

            map.put(a,i);
        }

        if(res == Integer.MAX_VALUE) System.out.println(-1);
        else System.out.println(res);
    }
}