#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, i, ara[200005], p;
  cin >> t;
  while (t--) {
    cin >> n;
    p = n - 1;
    for (i = 0; i < n; i++) cin >> ara[i];
    while (p > 0 && ara[p] <= ara[p - 1]) p--;
    while (p > 0 && ara[p] >= ara[p - 1]) p--;
    cout << p << '\n';
  }
  return 0;
}
