#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int up = 1, hill = 1;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] >= a[i + 1])
        up++;
      else
        break;
    }
    hill = up;
    for (int i = n - up; i >= 1; i--) {
      if (a[i] <= a[i + 1])
        hill++;
      else
        break;
    }
    cout << n - hill << endl;
  }
  return 0;
}
