#include <bits/stdc++.h>
using namespace std;
int la[200005];
int main() {
  int i, j, k;
  int n, m, mn;
  scanf("%d", &m);
  while (m--) {
    mn = 2e9;
    memset(la, 0, sizeof(la));
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      scanf("%d", &k);
      if (!la[k])
        la[k] = i;
      else {
        mn = min(mn, i - la[k]);
        la[k] = i;
      }
    }
    if (mn == 2e9)
      printf("-1\n");
    else
      printf("%d\n", mn + 1);
  }
  return 0;
}
