#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int temp = n - 1;
    for (int i = n - 2; i >= 0; i--) {
      if (arr[i] < arr[i + 1])
        break;
      else
        temp--;
    }
    while (temp > 0) {
      if (arr[temp - 1] <= arr[temp])
        temp--;
      else
        break;
    }
    cout << temp << endl;
  }
  return 0;
}
