#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, i;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    if (n == 1)
      cout << "-1" << endl;
    else {
      map<int, int> m;
      int c = 0, j = 0;
      for (i = 0; i < n; i++) {
        ++j;
        m[a[i]]++;
        if (m[a[i]] > 1) {
          c = j;
          m.clear();
          j = 0;
          m[a[i]]++;
          ++j;
        }
      }
      cout << c << endl;
    }
  }
  return 0;
}
