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