#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> arr) {
  int i = arr.size() - 1;
  while (i > 0 && arr[i] <= arr[i - 1]) i--;
  if (i == 0) return 0;
  while (i > 0 && arr[i] >= arr[i - 1]) i--;
  return i;
}
int main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int size;
    cin >> size;
    vector<int> arr;
    while (size--) {
      int tmp;
      cin >> tmp;
      arr.push_back(tmp);
    }
    cout << solve(arr) << endl;
  }
}
