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

public class Main {

    static FastReader in;
    static PrintWriter out;

    static void solve() {
        int n = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        ArrayList<Integer>[] x = new ArrayList[n + 1];
        Arrays.setAll(x, i -> new ArrayList<>());
        for (int i = 0; i < n; i++) {
            x[a[i]].add(i);
        }
        for (ArrayList<Integer> l : x) {
            Collections.sort(l);
        }

        int ans = -1;
        for (int i = 1; i <= n; i++) {

            for (int j = 1; j < x[i].size(); j++) {
                if (ans == -1 || x[i].get(j) - x[i].get(j - 1) + 1 < ans) {
                    ans = x[i].get(j) - x[i].get(j - 1) + 1;
                }
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("input.txt"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("output.txt"));

        int t = in.nextInt();

        while (t-- > 0)
            solve();

        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}