#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long n, i, j, ar[200001], x, a, b, y;
int main() {
  long long t;
  scanf("%lld", &t);
  while (t--) {
    vector<long long> vt[200001];
    scanf("%lld", &n);
    for (long long i = 0; i < n; i++) scanf("%lld", &ar[i]);
    long long mrk = -1, res = mod;
    long long cnt[200001] = {0};
    for (long long i = 0; i < n; i++) {
      cnt[ar[i]]++;
      vt[ar[i]].push_back(i);
    }
    for (long long i = 1; i < 200001; i++) {
      if (cnt[i] >= 2) {
        mrk = 1;
        for (long long j = 1; j < vt[i].size(); j++) {
          long long dis = (vt[i][j] - vt[i][j - 1]);
          if (dis < res) res = dis;
        }
      }
    }
    if (mrk == -1)
      cout << "-1\n";
    else
      cout << (res + 1) << "\n";
  }
}
