#include <bits/stdc++.h>
using namespace std;
const int MAXN = 210000;
int t, n, ans = 0;
int a[MAXN], maxl[MAXN], maxr[MAXN];
void solve() {
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int maxr = 0, minr = MAXN;
  for (int i = n; i >= 1; --i) {
    if (a[i] > minr) {
      ans = i;
      break;
    }
    if (maxr > a[i]) {
      minr = min(minr, a[i]);
    }
    maxr = max(maxr, a[i]);
  }
  printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
