import java.util.Scanner;
import java.util.*;

public class Solution {

	public static void main(String[] args) {
		boolean debug = false;

		Scanner input = new Scanner(System.in);

		int t = input.nextInt();

		for(int u = 0; u < t; u++) {
			int n = input.nextInt();

			int[] a = new int[n];

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

			HashMap<Integer, Integer> countMap = new HashMap<Integer, Integer>();

			int distance = -1;
			for(int i=0; i < n; i++) {
				if (countMap.get(a[i]) == null) {
					countMap.put(a[i], i);
				} else {
					Integer curVal = countMap.get(a[i]);
					distance = i - curVal + 1;
				}
			}

			System.out.println(distance);
		}
	}


}
