#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int j = -1;
  while (++j < t) {
    long n;
    cin >> n;
    vector<long> a(n), s(n + 1);
    long i = -1;
    while (++i < n) {
      cin >> a[i];
      s[a[i]]++;
    }
    if (n == 1) {
      cout << -1 << endl;
      continue;
    }
    i = -1;
    long f = 1, m = n + 10, k;
    for (i = 0; i < n - 1; ++i)
      for (k = i + 1; k < n && k - i < m; ++k)
        if (a[i] == a[k]) m = min(k - i, m);
    cout << m + 1 << endl;
  }
  return 0;
}
