import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class MainC {
    public static void main(String[] args) {
        MyScanner scanner = new MyScanner();

        int q = scanner.nextInt();
        for(int i = 0;i<q;i++){
            int n = scanner.nextInt();
            int[] array = new int[n];
            for(int j = 0;j<n;j++){
                array[j] = scanner.nextInt();
            }
            if(n < 2){
                System.out.println("-1");
                continue;
            }
            int min = Integer.MAX_VALUE;
            for(int j = 0;j<n;j++){
                Set<Integer> alreadyFound = new HashSet<>();
                for(int k = j;k<n;k++){
                    if(alreadyFound.contains(array[k])){
                        int currentLen = k-j + 1;
                        if(min > currentLen){
                            min = currentLen;
                        }
                        break;
                    }
                    alreadyFound.add(array[k]);
                }
            }
            System.out.println(min);
        }
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }
    // --------------------------------------------------------
}
