import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.attribute.FileAttribute;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.Arrays;

public class Main {


    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 void main(String[] args) {
        FastReader sc = new FastReader();
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int[] arr=new int[n];

            for(int j=0;j<n;j++){
                arr[j]=sc.nextInt();
            }
            if (n == 1) {
                System.out.println(-1);
                continue;
            }
            ArrayList<Integer> list = new ArrayList<>();
            int min=Integer.MAX_VALUE;
            for (int j = 0; j < n; j++) {
                int x=arr[j];
                        if(!list.contains(x)){
                            list.add(x);
                        }
                        else{
                            int index=list.lastIndexOf(x);
                            int diff=j-index+1;
                            if(diff<min){
                                min=diff;
                            }
                            list.add(x);
                        }
            }
            System.out.println(min);


        }

    }
}

