import java.util.*;

public class KosyaReshaetZadachi {

    public static void main (String[] args) {
        Scanner scan = new Scanner(System.in);

        long t = scan.nextLong();

        for(int q = 0; q < t; q++) {

            int n = scan.nextInt();
            int[][] arr = new int[n][2];

            for(int i = 0; i < n; i++) {
                arr[i][0] = scan.nextInt();
                arr[i][1] = i;
            }


            if(n < 2){
                System.out.println(-1);
                continue;
            }

            sort(arr, 0, n - 1);

            boolean change = false;
            int minLength = Integer.MAX_VALUE;
            int prevMin = Integer.MAX_VALUE;

            int len = 1;
            ArrayList<Integer> lens = new ArrayList<>();

            for(int i = 0; i < n - 1; i++) {
                if(arr[i][0] == arr[i + 1][0]){
                    len++;
                } else {
                    lens.add(len);
//                    System.out.print(len + " ");
                    len = 1;
                }
            }

            lens.add(len);
//            System.out.print(len + " ");
//            System.out.println();

            for (int i = 0; i < lens.size(); i++) {
                int cur = lens.get(i);
                if (cur != 1) {
                    change = true;
                    for (int j = 0; j < cur; j++) {
                        for (int k = j + 1; k < cur; k++) {
                            if (Math.abs(arr[k + i][1] - arr[j + i][1]) <= minLength) {

                                if(change) {
                                    prevMin = minLength;
                                    change = false;
                                }

                                minLength = Math.abs(arr[k + i][1] - arr[j + i][1]);
                            }
                        }
                    }
                }
            }

            if(minLength == Integer.MAX_VALUE || minLength == prevMin){
                System.out.println(-1);
            } else {
                System.out.println(minLength + 1);
            }

        }
    }

    private static int partition(int arr[][], int low, int high)
    {
        int pivot = arr[high][0];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            // If current element is smaller than the pivot
            if (arr[j][0] < pivot)
            {
                i++;

                // swap arr[i] and arr[j]
                int[] temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }

        // swap arr[i+1] and arr[high] (or pivot)
        int[] temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;

        return i+1;
    }


    /* The main function that implements QuickSort()
      arr[] --> Array to be sorted,
      low  --> Starting index,
      high  --> Ending index */
    private static void sort(int[][] arr, int low, int high)
    {
        if (low < high)
        {
            /* pi is partitioning index, arr[pi] is
              now at right place */
            int pi = partition(arr, low, high);

            // Recursively sort elements before
            // partition and after partition
            sort(arr, low, pi-1);
            sort(arr, pi+1, high);
        }
    }

//    static long gcd(long a, long b)
//    {
//        if (a == 0)
//            return b;
//        return gcd(b % a, a);
//    }
//
//    static long findGCD(ArrayList<Long> arr, long n)
//    {
//        long result = arr.get(0);
//
//        for (int i = 1; i < n; i++) {
//            result = gcd(arr.get(i), result);
//
//            if(result == 1){
//                break;
//            }
//        }
//
//        return result;
//    }

}