#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
long long power(long long x, long long y) {
  long long v = 1;
  while (y > 0) {
    if (y & 1) v = v * x;
    y = y >> 1;
    x = x * x;
  }
  return v;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long ceil(long long a, long long b) { return (a + b - 1) / b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long test = 1;
  cin >> test;
  while (test--) {
    long long n;
    cin >> n;
    map<long long, long long> mp;
    long long mini = INT_MAX;
    long long i = 1;
    while (i <= n) {
      long long x;
      cin >> x;
      if (mp[x] != 0) {
        mini = min(mini, i - mp[x]);
      }
      mp[x] = i;
      i++;
    }
    if (mini == INT_MAX)
      cout << -1 << "\n";
    else
      cout << mini + 1 << "\n";
  }
  return 0;
}
