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