#include <bits/stdc++.h>
using namespace std;
long long t, a[200009], b, i, n, p;
int main() {
  cin >> t;
  while (t--) {
    p = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    p = n - 1;
    while (p && a[p] <= a[p - 1]) p--;
    while (p && a[p] >= a[p - 1]) p--;
    cout << p << "\n";
  }
}
