#include <bits/stdc++.h>
using namespace std;
void fun(multiset<pair<long long int, long long int> > ms, long long int n) {
  int sz = ms.size();
  long long int i, ans = INT_MAX, d;
  if (n == 1) {
    cout << "-1\n";
    return;
  }
  multiset<pair<long long int, long long int> >::iterator it;
  multiset<pair<long long int, long long int> >::iterator t;
  for (it = ms.begin(); it != ms.end(); it++) {
    t = next(it, 1);
    if (t == ms.end()) break;
    if ((*it).first == (*t).first) {
      d = (*t).second - (*it).second;
      if (d <= ans && d >= 1) {
        ans = d;
      }
    }
  }
  ans = d + 1;
  if (d == INT_MAX) ans = -1;
  cout << ans;
  cout << "\n";
}
int main() {
  long long int t, n, x, y, z, i, sum;
  cin >> t;
  while (t--) {
    cin >> n;
    multiset<pair<long long int, long long int> > ms;
    for (i = 0; i < n; i++) {
      cin >> x;
      ms.insert(make_pair(x, i));
    }
    fun(ms, n);
    ms.clear();
  }
  return 0;
}
