#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) cin >> a[i];
  int up = 0, down = 0, i = n - 2, flag = 0;
  for (i = n - 2; i >= 0; i--) {
    if (a[i] > a[i + 1]) {
      if (down == 1) {
        i += 1;
        break;
      }
      up = 1;
    }
    if (a[i] < a[i + 1]) {
      down = 1;
    }
  }
  if (i <= 0) i = 0;
  cout << i;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
