#include <bits/stdc++.h>
using namespace std;
int t, n, a[233333], k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    k = n;
    while (a[k - 1] >= a[k] && k > 1) k--;
    while (a[k - 1] <= a[k] && k > 1) k--;
    printf("%d\n", k - 1);
  }
  return 0;
}
