#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    reverse(v.begin(), v.end());
    int s = 1;
    int prev = v[0];
    while (prev <= v[s] && s < n) {
      prev = v[s];
      s++;
    }
    prev = v[s];
    if (s < n) s++;
    while (prev >= v[s] && s < n) {
      prev = v[s];
      s++;
    }
    cout << n - s << "\n";
  }
}
