#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> a(200010);
void testCase() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long index = n - 1;
  for (long long i = n - 2; i >= 0; i--) {
    if (a[i] >= a[i + 1])
      index = i;
    else
      break;
  }
  for (long long i = index - 1; i >= 0; i--) {
    if (a[i] <= a[i + 1])
      index = i;
    else
      break;
  }
  cout << index << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    testCase();
  }
  return 0;
}
