//package EducationalRound76;

import java.util.*;
import java.io.*;

public class DominatedSubarray {

    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        for(int query = 0; query < t; query++){
            int min = Integer.MAX_VALUE;
            int[] lastOccurance = new int[200001];
            Arrays.fill(lastOccurance,-1);
            int n = sc.nextInt();
            for(int i = 0; i<n; i++){
                int k = sc.nextInt();
                if(lastOccurance[k] > -1){
                    min = Math.min(min, i - lastOccurance[k] + 1);
                    lastOccurance[k] = i;
                }
                else{
                    lastOccurance[k] = i;
                }
            }
            if(min == Integer.MAX_VALUE){
                pw.println(-1);
            }
            else{
                pw.println(min);
            }
        }
        pw.close();
    }

    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;
        }
    }
}