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