import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.nextInt();
            for (int d = 0; d <t ; d++){
                int n = in.nextInt();
                int ans = -1;
                int[] arr = new int[n+1];
                for (int i = 1; i <=n ; i++) {
                    arr[i]=-1;
                }
                for (int i = 0; i <n; i++) {
                    int v = in.nextInt();
                    if (arr[v] == -1) arr[v]=i;
                    else {
                        if (ans == -1) ans=i-arr[v]+1;
                        else if (i-arr[v]+1 < ans) ans = i-arr[v]+1;
                        arr[v]=i;
                    }
                }
                out.println(ans);
            }
        }
    }
    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());
        }
        public long nextLong() { return Long.parseLong(next());
        }



    }

}

