#include <bits/stdc++.h>
using namespace std;
void showvec(vector<long long> &arr);
inline void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> arr(200005);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    fill(arr.begin(), arr.end(), -1);
    long long ans = INT_MAX;
    for (long long i = 0; i < n; i++) {
      long long ele;
      cin >> ele;
      if (arr[ele] != -1) {
        ans = min(ans, i - arr[ele] + 1);
      }
      arr[ele] = i;
    }
    cout << (ans == INT_MAX ? -1 : ans);
    cout << "\n";
  }
  return 0;
}
