#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ;
  long long int t, i;
  cin >> t;
  while (t--) {
    long long int n, x, tt = 0;
    vector<pair<long long int, long long int>> v, v1;
    multimap<long long int, long long int> m, u;
    multiset<long long int> s;
    cin >> n;
    for (long long int i = 0; i < n; i++) {
      cin >> x;
      v.push_back({x, i});
      m.insert({x, i});
    }
    long long int c = 0, a, b, min = INT_MAX, j, k;
    if (n < 2) {
      cout << "-1" << '\n';
      continue;
    } else {
      sort((v).begin(), (v).end());
      for (long long int j = 0; j < v.size() - 1; j++) {
        if (v[j].first != v[j + 1].first)
          continue;
        else {
          tt = 1;
          for (long long int k = j + 1; k < v.size(); k++) {
            if (v[j].first == v[k].first)
              c = v[k].second - v[j].second;
            else
              break;
            if (c == 1) {
              min = c;
              break;
            } else if (c < min)
              min = c;
          }
        }
      }
      if (tt == 0)
        cout << "-1" << '\n';
      else
        cout << min + 1 << '\n';
    }
  }
  return 0;
}
