#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a[n + 1];
  long long int test;
  for (long long int i = 0; i < (n); i++) {
    cin >> test;
    a[test].push_back(i);
  }
  long long int temp, mini = -1;
  for (long long int i = 0; i < (n + 1); i++) {
    if (a[i].size() > 1) {
      temp = a[i][1] - a[i][0] + 1;
      if (mini == -1) {
        mini = temp;
      }
      for (long long int j = 0; j < (a[i].size() - 1); j++) {
        temp = a[i][j + 1] - a[i][j] + 1;
        mini = (mini < temp ? mini : temp);
      }
    }
  }
  cout << mini << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
