#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int ans = 0;
  int i = 2;
  if (n < 2) {
    cout << -1 << endl;
    return;
  }
  while (i != n) {
    int j = 0;
    while (j < n - i + 1) {
      if (v[j] == v[j + i - 1]) {
        cout << i << endl;
        return;
      }
      j++;
    }
    i++;
  }
  cout << n << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t) {
    solve();
    t--;
  }
  return 0;
}
