#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205000;
int tn;
int n;
int a[MAXN];
int last[MAXN];
int main() {
  scanf("%d", &tn);
  while (tn--) {
    scanf("%d", &n);
    int mn = -1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      last[i + 1] = -1;
    }
    for (int i = 0; i < n; i++) {
      if (last[a[i]] != -1) {
        int cur = i - last[a[i]] + 1;
        if (mn == -1 || (mn > cur)) {
          mn = cur;
        }
      }
      last[a[i]] = i;
    }
    printf("%d\n", mn);
  }
  return 0;
}
