#include <bits/stdc++.h>
using namespace std;
long long int modularExponentiation(long long int n, long long int p,
                                    long long int M) {
  long long int res = 1;
  while (p) {
    if (p & 1) res = (res * n) % M;
    n = (n * n) % M;
    p >>= 1;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int cur = n - 1;
  while (cur > 0 && a[cur - 1] >= a[cur]) cur--;
  while (cur > 0 && a[cur - 1] <= a[cur]) cur--;
  cout << cur << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
