#include <bits/stdc++.h>
using namespace std;
int findthedistance(int arr[], vector<int> hash, int n) {
  int ans = 1000000;
  for (int i = 0; i < n; i++) {
    if (hash[arr[i]] == -1)
      hash[arr[i]] = i;
    else {
      int curr_ans = i - hash[arr[i]];
      ans = min(curr_ans, ans);
      hash[arr[i]] = i;
    }
  }
  if (ans == 1000000) {
    return -1;
  } else {
    return ans + 1;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<int> hash(100000, -1);
    cout << findthedistance(arr, hash, n) << endl;
  }
}
