#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int num[100002 << 1], s[100002 << 1];
int main(void) {
  int t, n, minn;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    minn = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      s[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &num[i]);
      if (s[num[i]]) {
        minn = min(minn, i - s[num[i]]);
      }
      s[num[i]] = i;
    }
    if (minn == 0x3f3f3f3f) {
      puts("-1");
    } else {
      printf("%d\n", minn + 1);
    }
  }
  return 0;
}
