#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> arr(n);
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    long long int i = n - 1;
    while (i > 0 && arr[i - 1] >= arr[i]) {
      i--;
    }
    while (i > 0 && arr[i - 1] <= arr[i]) {
      i--;
    }
    long long int final = i;
    cout << final << endl;
  }
}
