#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, tmp;
    cin >> n;
    vector<long long> v;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      v.push_back(tmp);
    }
    vector<long long> ans[200001];
    for (int i = 0; i < n; i++) {
      ans[v[i]].push_back(i);
    }
    long long mn = LONG_MAX;
    long long flag = 0;
    for (int i = 0; i < 200001; i++) {
      if (ans[i].size() >= 2) {
        for (int j = 0; j < ans[i].size() - 1; j++) {
          mn = min(mn, ans[i][j + 1] - ans[i][j]);
        }
        flag = 1;
      }
    }
    if (flag == 0)
      cout << -1 << endl;
    else
      cout << mn + 1 << endl;
  }
  return 0;
}
