#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int T, n, last[N], a[N], ans;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    fill(last, last + N, 0);
    ans = -1;
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &a[i]);
      if (last[a[i]] == 0)
        last[a[i]] = i;
      else {
        int now = i - last[a[i]] + 1;
        if (ans == -1)
          ans = now;
        else
          ans = min(ans, now);
        last[a[i]] = i;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
