#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 100;
long long t, n;
long long a[maxx], vis[maxx];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> t;
  while (t--) {
    cin >> n;
    memset(vis, 0, sizeof vis);
    memset(a, 0, sizeof a);
    long long num = -1, va = 0;
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << "-1" << endl;
      continue;
    } else {
      long long l, ans = maxx;
      for (int i = 1; i <= n; i++) {
        if (!vis[a[i]]) {
          vis[a[i]] = i;
        } else {
          ans = min(ans, i - vis[a[i]] + 1);
          vis[a[i]] = i;
        }
      }
      if (ans == maxx) {
        cout << -1 << endl;
      } else {
        cout << ans << endl;
      }
    }
  }
  return 0;
}
