#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e5 + 7;
const int N = 56;
int t, a[maxn];
void work() {
  int n;
  cin >> n;
  int m = -2;
  for (int i = 1; i <= n; i++) a[i] = -1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (a[x] > -1 && (m == -2 || m > i - a[x])) m = i - a[x];
    a[x] = i;
  }
  cout << m + 1 << endl;
}
int main() {
  cin >> t;
  while (t--) work();
  return 0;
}
