#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n;
    std::vector<pair<long long, long long> > v;
    for (int i = 0; i < n; i++) {
      cin >> x;
      v.push_back({x, i});
    }
    if (n < 2) {
      cout << -1 << endl;
      continue;
    }
    long long mini = INT_MAX;
    for (int i = 1; i < v.size(); i++) {
      if (v[i].first == v[i - 1].first) {
        mini = min(mini, v[i].second - v[i + 1].second);
      }
    }
    if (mini == INT_MAX) {
      mini = -1;
    }
    cout << mini << endl;
  }
}
