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