#include <bits/stdc++.h>
using namespace std;
unsigned long long int bolpow(unsigned long long int a,
                              unsigned long long int b,
                              unsigned long long int m) {
  a %= m;
  unsigned long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res % m;
}
bool isPrime(unsigned long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (unsigned long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int subArrayLength(int arr[], int n) {
  int minLen = INT_MAX;
  map<int, int> last;
  for (int i = 0; i < n; i++) {
    if (last[arr[i]] != 0) {
      minLen = min(minLen, i - last[arr[i]] + 2);
    }
    last[arr[i]] = i + 1;
  }
  if (minLen == INT_MAX) {
    return -1;
  }
  return minLen;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    cout << subArrayLength(a, n) << endl;
  }
  return 0;
}
