#include <bits/stdc++.h>
using namespace std;
void solvere() {
  long long int i, j, m, t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    m = n;
    vector<long long int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < i + m - 1 && j < n; j++)
        if (a[i] == a[j]) {
          m = j - i + 1;
          break;
        }
    }
    if (m != 1)
      cout << m << "\n";
    else
      cout << -1 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solvere();
  return 0;
}
