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