import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.sqrt; 
import static java.lang.Math.floor; 
import static java.lang.Math.abs;

public class cf { 
    static final double EPS = 1e-6;
    final static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    final static Scanner sc=new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        // int t=Integer.parseInt(br.readLine());
        int t=sc.nextInt();
        
         while (t-->0) {
            // int[] input=sia(2);
            int n=sc.nextInt();
            int [] a=siasc(n);
            if (n==1) {
                System.out.println(-1);
                continue;
            }int ans=10000000;
            for (int i = 0; i < a.length; i++) {
                int j,jj=-1;
                for (j = i+1; j < a.length; j++) {
                    if (a[i]==a[j]) {
                        jj=j;
                        break;
                    }
                }
                if (jj!=-1&&ans>jj-i+1) {
                    ans=j-i+1;
                }
            }
           System.out.println(ans);
           }
        //System.out.println(primeFactors(sc.nextLong()));
        
        
    }
public static int[] siasc(int n) {
        int[] a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextInt();
        }
        return a;
    }
static int[] getArr(BigInteger num)
{
    String str = num.toString();
    int[] arr = new int[str.length()];
    for (int i=0; i<arr.length; i++)
         arr[i] = str.charAt(i)-'0';
    return arr;
}
static int min(Queue<Integer> q){
    int min=10000;
    for (Integer var : q) {
        min=Math.min(min, var);
    }
    return min;
}
public static int[] sia(int n)  throws Exception{ 
    int a[] = new int[n];
            String line = br.readLine(); 
            String[] strs = line.trim().split("\\s+");
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(strs[i]);
            }
            return a;
}
public static String baseConversion(String number,int sBase, int dBase) 
{ 
    // Parse the number with source radix  
    // and return in specified radix(base) 
    return Long.toString(Long.parseLong(number, sBase),dBase); 
}


static long phi(long n) 
{ 
    
    long result = n;  
    long m=n;
  
    
    for (long p = 2; p * p <= n; ++p) 
    { 
          
        if (n % p == 0)  
        { 
              
            
            while (n % p == 0) 
                n /= p; 
            result -= result / p; 
        } 
    } 
  
  
    if (n > 1) 
        result -= result / n; 
    if(result==m-1)
    result++;
    return result; 
} 

 static long primeFactors(long n) 
    { 
        long m=n;
        if (n%2==0) {
            m-=n/2;
        }
        while (n%2==0) 
        { 
            
            n /= 2; 
        } 
  
        for (int i = 3; i <= Math.sqrt(n); i+= 2) 
        { 
            while (n%i == 0) 
            { 
                m-=n/i;
                n /= i; 
            } 
        } 
        if (n > 2) 
            return m-n/n; 
            return m+1;
    } 
   
}

