#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int mod = 1e9 + 7, N = 2e5 + 5, inf = 1e9;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, arr[N];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    int i = n - 2;
    for (; i >= 0 && arr[i] >= arr[i + 1]; i--)
      ;
    for (; i >= 0 && arr[i] <= arr[i + 1]; i--)
      ;
    cout << i + 1 << '\n';
  }
  return 0;
}
