#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a, b, x, d, k = 100002, i, t, j, f = 0, ff = 0;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n;
    map<long long int, pair<long long int, long long int>> m;
    for (j = 0; j < n; j++) {
      cin >> x;
      if (m.find(x) == m.end())
        m[x] = make_pair(j, 100002);
      else {
        f = j - m[x].first;
        m[x].first = j;
        if (f <= m[x].second) m[x].second = f;
        k = min(k, m[x].second);
      }
    }
    if (k == 100002)
      cout << -1;
    else
      cout << k + 1;
    cout << endl;
  }
  return 0;
}
