#include <bits/stdc++.h>
using namespace std;
void pb_200() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  long long int x;
  cin >> x;
  while (x--) {
    long long int n;
    cin >> n;
    long long int *arr = new long long int[n];
    ;
    for (long long int i = 0; i < n; ++i) cin >> arr[i];
    long long int i = n - 1;
    while (i > 0 and arr[i] <= arr[i - 1]) i--;
    if (i == 0) {
      cout << 0 << endl;
      continue;
    }
    while (i > 0 and arr[i] >= arr[i - 1]) i--;
    cout << i << endl;
  }
}
