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