import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class DominatedSubarray {

    @SuppressWarnings("Duplicates")
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        //        InputStream inputStream = new FileInputStream(new File("test.in"));
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int tests = in.nextInt();
        solve(tests, in, out);
        out.close();
    }

    static void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
        for (int ii = 0; ii < testNumber; ii++) {
            int n=in.nextInt(), max=Integer.MAX_VALUE, pos=-1;
            boolean uni = false;
            ArrayList<Integer> a = new ArrayList<>(n);
            Map<Integer,Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                a.add(in.nextInt());
                if(!map.containsKey(a.get(i)))
                    map.put(a.get(i),i);
                else{
                    int temp = i-map.get(a.get(i))+1;
                    map.put(a.get(i),i);
                    max=Math.min(max,temp);
                }
            }
            if(max==Integer.MAX_VALUE)
                System.out.println(-1);
            else
                System.out.println(max);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}
