#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void test_case() {
  int n;
  cin >> n;
  int a[n];
  for (int i = (0); i < (n); ++i) {
    cin >> a[i];
  }
  int r = n - 1;
  while (r >= 1 && a[r - 1] >= a[r]) r--;
  while (r >= 1 && a[r - 1] <= a[r]) r--;
  cout << r << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) test_case();
}
