#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long mxn = 2e5 + 10;
long long tc, n, xend, a[mxn];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  cout.setf(ios::fixed);
  cout.precision(0);
  cin >> tc;
  while (tc != 0) {
    tc--;
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    xend = n - 1;
    while (a[xend] >= a[xend + 1] && xend != 0) xend--;
    while (a[xend] >= a[xend - 1] && xend != 0) xend--;
    if (xend == 0)
      cout << 0 << '\n';
    else
      cout << xend - 1 << '\n';
  }
  return 0;
}
