#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};
int solve(int N, const vector<int>& xs) {
  auto R = N - 1;
  while (R > 0 and xs[R - 1] >= xs[R]) --R;
  while (R > 0 and xs[R - 1] <= xs[R]) --R;
  return R;
}
int main() {
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector<int> xs(N);
    for (int i = 0; i < N; ++i) cin >> xs[i];
    auto ans = solve(N, xs);
    cout << ans << '\n';
  }
  return 0;
}
