1
3
5 3 4
 6
5
5 3 4 4 5
3
1 1 1
5
4 4 3 4 4
5
5 5 4 3 2
3
1 1 2
5
5 4 3 5 5
 1
3
10 1 5

1
 1
-1
2
2
3
1
 1

#include <bits/stdc++.h>
using vi = std::vector<long long int>;
using vvi = std::vector<vi>;
using pii = std::pair<long long int, long long int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
using namespace std;
const long long int N = 2e6 + 10;
const long long int inf = 1e18 + 10;
const long double Pi = 3.14159265;
long long int n, A[N];
pii b[N];
vvi a;
long long int vis[N];
void dfs(long long int j) {
  if (vis[j] == 1) return;
  vis[j] = 1;
  vpii tmp;
  if (j != 1 and a[j - 1] > a[j]) tmp.emplace_back(A[j - 1], j - 1);
  if (j != n and a[j + 1] > a[j]) tmp.emplace_back(A[j + 1], j + 1);
  sort(tmp.begin(), tmp.end());
  for (auto i : tmp)
    if (vis[i.second] == 0) {
      ++A[i.second];
      dfs(i.second);
    }
  return;
}
void solve() {
  cin >> n;
  map<long long int, vi> ma;
  a.resize(n + 1);
  fill(vis, vis + n + 1, 0);
  for (long long int i = 1; i <= n; i++) cin >> A[i];
  for (long long int i = 1; i <= n; i++) b[i] = {A[i], i};
  sort(b + 1, b + 1 + n);
  for (long long int i = 1; i <= 1; i++) dfs(b[i].second);
  for (long long int i = 1; i <= n; i++) ma[A[i]].emplace_back(i);
  if (ma.size() <= 1) {
    cout << -1;
    return;
  }
  sort((*ma.rbegin()).second.begin(), (*ma.rbegin()).second.end());
  cout << ((*ma.rbegin()).second)[((*ma.rbegin()).second).size() / 2];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int xx = 0;
  long long int t;
  cin >> t;
  while (t--) {
    ;
    solve();
    cout << endl;
  }
  return 0;
}
