#include <bits/stdc++.h>
using namespace std;
int q;
int n;
int nav[200005], pos[200005];
int main() {
  scanf("%d", &q);
  while (q--) {
    int men = 999999, lar = 999999;
    scanf("%d", &n);
    int a;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      if (nav[a] == 0) nav[a] = 1, pos[a] = i;
      if (nav[a] == 1) lar = i - pos[a], pos[a] = i;
      if (lar < men && lar != 0) men = lar;
    }
    printf("%d\n", men == 999999 ? -1 : men + 1);
    for (int i = 0; i < 200001; i++) nav[i] = pos[i] = 0;
  }
  return 0;
}
