#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  scanf("%d", &n);
  int maxi = 0;
  int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  int i;
  for (i = n - 1; i > 0 && arr[i - 1] >= arr[i]; i--)
    ;
  for (; i > 0 && arr[i - 1] <= arr[i]; i--)
    ;
  printf("%d\n", i);
  return;
}
int main() {
  int t, z = 1;
  scanf("%d", &t);
  while (z <= t) {
    solve();
    z++;
  }
  return 0;
}
