

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class NewMain
{
    public static void main(String[] args) throws IOException
    { 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        while(t-->0)
        {
            int n = Integer.parseInt(br.readLine());
            int min=Integer.MAX_VALUE;
            String[] input=br.readLine().split(" ");
            Map<Integer,Integer> map = new HashMap<>();
            for(int i=0;i<n;i++)
            {
                int a = Integer.parseInt(input[i]);
                if(map.containsKey(a))
                    min=Math.min(min, i-map.get(a));
                map.put(a,i);
            }
            if(min!=Integer.MAX_VALUE)
                System.out.println(min+1);
            else
                System.out.println(-1);
        }
        
        
    }
}
