#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long *arr = new long long[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long i = n - 1;
  while (i > 0) {
    if (arr[i - 1] >= arr[i]) {
      i--;
    } else {
      break;
    }
  }
  while (i > 0) {
    if (arr[i - 1] <= arr[i]) {
      i--;
    } else {
      break;
    }
  }
  cout << i << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
