#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int i = n - 2;
    while (i >= 0 && a[i] >= a[i + 1]) i--;
    while (i >= 0 && a[i] <= a[i + 1]) i--;
    cout << i + 1 << endl;
  }
  return 0;
}
auto x = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
