#include <bits/stdc++.h>
using namespace std;
long long countfactor(long long n) {
  long long count = 0;
  long long t = 0;
  long long num = 0;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      long long temp = n;
      while (temp % i == 0) {
        temp = temp / i;
        count++;
      }
    }
    if (count > t) {
      num = i;
    }
    t = max(t, count);
    count = 0;
  }
  return num;
}
int binomialCoeff(int n, int k) {
  if (k > n) return 0;
  if (k == 0 || k == n) return 1;
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void check(vector<int> A, int i, int n) {}
void solve() {
  long long t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
      cin >> A[i];
    }
    int j = n - 1;
    while (j - 1 >= 0) {
      if (A[j - 1] >= A[j]) {
        j--;
      } else
        break;
    }
    while (j - 1 >= 0) {
      if (A[j - 1] <= A[j])
        j--;
      else
        break;
    }
    cout << j << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
