#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n + 5];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    int p = n;
    while (p > 1 && arr[p] <= arr[p - 1]) {
      p--;
    }
    while (p > 1 && arr[p] >= arr[p - 1]) {
      p--;
    }
    if (p == 0) {
      cout << 0 << endl;
    } else {
      cout << p - 1 << endl;
    }
  }
  return 0;
}
