#include <bits/stdc++.h>
using namespace std;
int l[200005];
int main() {
  ios_base::sync_with_stdio(false);
  int t, n, i, x, ans;
  cin >> t, n, i;
  while (t--) {
    cin >> n;
    ans = INT_MAX;
    memset(l, 0, sizeof(l));
    for (i = 1; i <= n; i++) {
      cin >> x;
      if (l[x]) ans = min(ans, abs(l[x] - i) + 1);
      l[x] = i;
    }
    if (ans == INT_MAX) ans = -1;
    cout << ans << endl;
  }
  return 0;
}
