#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1000;
const int inf = 1e9;
int a[maxn];
int N;
int b;
int minn;
int n;
int main() {
  scanf("%d", &N);
  for (int k = 1; k <= N; k++) {
    memset(a, 0, sizeof(a));
    minn = inf;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b);
      if (a[b] != 0) {
        minn = min(minn, i - a[b] + 1);
      }
      a[b] = i;
    }
    if (minn == inf)
      cout << "-1" << endl;
    else
      cout << minn << endl;
  }
  return 0;
}
