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

public class dominated_subarray {
	public void run() throws Exception {
		FastReader file = new FastReader();
		int times = file.nextInt();
		for (int asdf = 0; asdf < times; asdf++) {
			int n = file.nextInt();
			int min = Integer.MAX_VALUE;
			HashMap<Integer, Integer> loc = new HashMap();
			for (int i = 0; i < n; i++) {
				int cur = file.nextInt();
				if (!loc.containsKey(cur)) {
					loc.put(cur, i);
				}
				else {
					min = Math.min(min, i - loc.get(cur) + 1);
					loc.put(cur, i);
				}
			}
			System.out.println(min == Integer.MAX_VALUE ? -1 : min);
		}
	}

	public static void main(String[] args) throws Exception {
		new dominated_subarray().run();
	}

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