import java.util.*;
import java.io.*;
public class c {
    public static PrintWriter out;
    public static void main(String[] args) throws IOException {
        FS sc = new FS(System.in);
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            int [] ar = new int[n];
            Map<Integer, Integer> prev = new HashMap<>();
            int min = (int)2E5 + 20;
            boolean found = false;
            for (int i=0;i<n;i++) {
                ar[i] = sc.nextInt();
                if (prev.containsKey(ar[i])) {
                    found = true;
                    min = Math.min(min, i - prev.get(ar[i]));     
                }
                prev.put(ar[i], i);
            }
            if (!found) out.println(-1);
            else out.println(min+1);
        }
        out.close();
    }
    
    static class FS {
    	BufferedReader br;
        StringTokenizer st;

    	public FS(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
	        st = new StringTokenizer("");
        }

        public String next() throws IOException {
            if(st.hasMoreTokens())
                return st.nextToken();
    	    else
                st = new StringTokenizer(br.readLine());
            return next();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
	
        public long nextLong() throws IOException {
            return Long.parseLong(next());
    	}

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }
}
