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 namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int ara[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> ara[i];
    }
    int cnt = 0;
    int cnt2 = 0;
    int mx = 0;
    for (int i = 1; i < n; i++) {
      if (ara[i + 1] > ara[i]) {
        cnt = i + 1;
      } else if (ara[i] > ara[i + 1]) {
        cnt2 = i;
      }
    }
    if (cnt >= cnt2) {
      mx = cnt;
    } else {
      mx = cnt2;
    }
    if (mx > 0) {
      cout << mx << endl;
    } else {
      cout << "-1" << endl;
    }
  }
  return 0;
}
