#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back({a[i], i + 1});
  }
  sort(v.begin(), v.end());
  long long ans = INT_MAX, flag = 0;
  for (long long i = 0; i < (long long)((v).size()) - 1; i++) {
    if (v[i].first == v[i + 1].first) {
      flag = 1;
      ans = min(ans, v[i + 1].second - v[i].second);
    }
  }
  if (!flag)
    cout << "-1" << '\n';
  else {
    cout << ans + 1 << '\n';
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
