//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;


public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    static int[] splitBinary(String s,int l){
        int holder[] = new int[l];
        String []temp = s.split("");
        for(int i = 0; i < temp.length; i++){
            holder[i] = Integer.parseInt(temp[i]);
        }
        return holder;
    }
    static long[] digitSum(long n) {
        ArrayList<Long> sum = new ArrayList<>();
        long minMax[] = new long[2];
        minMax[0] = Long.MAX_VALUE;
        while (n != 0) {
            minMax[0] = Math.min(minMax[0],n%10 );
            minMax[1] = Math.max(minMax[1],n%10 );
            n /= 10;
        }
        return minMax;
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int n = scanner.nextInt();
        while(n-->0){
            int number = scanner.nextInt();
            int arr[] = new int[number];
            int result = Integer.MAX_VALUE;
            for(int i = 0; i < number; i++)
                arr[i] = scanner.nextInt();
            HashMap<Integer,Integer> holder = new HashMap<>();
            for(int i = 0; i < number; i++){
                if (holder.containsKey(arr[i])) {
                    result = Math.min(i - holder.get(arr[i]) + 1, result);
                }
                holder.put(arr[i],i);
            }
            if(arr.length == 1){
                out.println(-1);
            }else{
                out.println(result);
            }
        }

        out.flush();
        out.close();
    }
}