#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}
unordered_map<string, int> X;
void solve() {
  int n, flag = 0, change = 2, final = 0, temp;
  cin >> n;
  vector<pair<int, int>> A;
  unordered_map<int, int> X;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (i != 0) {
      if (temp != A.back().first) {
        A.push_back({temp, i});
      }
    } else {
      A.push_back({temp, i});
    }
  }
  for (int i = 1, z, j; i < A.size() - 1; i++) {
    j = i + 1;
    z = i - 1;
    if (A[i].first < A[j].first && A[i].first < A[z].first) {
      final = A[i].second;
    }
  }
  cout << final << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
