#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n], tmp, min = 1000000000, minval;
    int domination = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      arr[i] = tmp;
      for (int j = 0; j < i; j++) {
        if (arr[i] == arr[j] && i - j + 1 < min) {
          min = i - j + 1;
          flag = true;
          minval = arr[i];
        } else if (arr[i] == arr[j] && i - j + 1 == min) {
          if (minval != arr[i]) {
            min = 1000000000;
            flag = false;
          }
        }
      }
    }
    if (flag) {
      cout << min << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
