#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;
  vector<int> v;
  map<int, int> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    m[a[i]]++;
  }
  if (n == 1) {
    printf("-1\n");
    return;
  }
  int val, num = -1e9;
  for (int i = 1; i <= n; i++)
    if (m[a[i]] > num) val = a[i], num = m[a[i]];
  for (int i = 1; i <= n; i++)
    if (a[i] == val) v.push_back(i);
  int ans = 1e9;
  for (int i = 1; i < v.size(); i++) ans = min(v[i] - v[i - 1], ans);
  cout << ans + 1 << endl;
}
int main() {
  cin >> t;
  while (t--) work();
  return 0;
}
