import java.io.*;
import java.util.*;
 
public class domSubarray {
 
	public static void main(String[] args) throws FileNotFoundException {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int n=sc.nextInt();
		for(int i=0;i<n;i++) {
			Map<Integer, ArrayList<Integer>> list = new HashMap<Integer, ArrayList<Integer>>();
			int len = sc.nextInt();
			int min=Integer.MAX_VALUE;
			for(int j=0;j<len;j++) {
				int next=sc.nextInt();
				ArrayList<Integer> temp = new ArrayList<Integer>();
				if(list.get(next)!=null) {
					int kek=1+(j-list.get(next).get(list.get(next).size()-1));
					min=kek<min ? kek : min;
					temp=list.get(next);
				}
				temp.add(j);
				list.put(new Integer(next),temp);
			}
			if(min==Integer.MAX_VALUE)
				min=-1;
			pw.println(min);
		}
		pw.close();
	}
}
 
//fastscanner stuff stolen from caleb
@SuppressWarnings("all")
class FastScanner {
    BufferedReader br;
    StringTokenizer st;
    public FastScanner(BufferedReader d) {
        br=d;
    }
    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    } 
    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
    int nextInt() {
        return Integer.parseInt(nextToken());
    } 
    long nextLong() {
        return Long.parseLong(nextToken());
    }
    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}