import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef{
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String ns() {
		while(st==null||!st.hasMoreElements())
		{
			try{
			st = new StringTokenizer(br.readLine());
			}catch (IOException e) {
                e.printStackTrace();
            }
		}
		return st.nextToken();
		
	}

	String nextLine() throws Exception{
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }

	int nextInt(){
		return Integer.parseInt(ns());
	}

	long nextLong() {
        return Long.parseLong(ns());
    }

	double nextDouble(){
		return Double.parseDouble(ns());	
	}

	public static void main(String str[]) throws IOException
	{
		new Codechef().run();
	}

	void run() throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		out=new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();
	}

	int gcd(int sum,int n)
	{
		if(sum%n==0)
			return n;
		else
			return gcd(n,sum%n);
	}

	void solve()
	{
		int q=nextInt();
		while(q-->0)
		{
			int n=nextInt();
			int arr[]= new int[n];

			for(int i=0;i<n;i++)
				arr[i]=nextInt();

			int ans=Integer.MAX_VALUE;
			HashMap<Integer,Integer> map = new HashMap<>();

			for(int i=0;i<n;i++)
			{
				if(!map.containsKey(arr[i]))
					map.put(arr[i],i);
				else{
					ans=Math.min(ans,(i-map.get(arr[i])+1));
					map.put(arr[i],i);
				}
			}
			if(ans==Integer.MAX_VALUE)
				ans=-1;
			out.println(ans);

		}
		
	}
}