#include <bits/stdc++.h>
using namespace std;
int t, x, y, z, n;
int a[200005];
int main() {
  cin >> t;
  while (t--) {
    scanf("%d", &n);
    z = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int now = 0;
    int flag = 0;
    for (int i = n - 1; i >= 1; i--) {
      if (now == 0) {
        if (a[i] >= a[i + 1])
          continue;
        else
          now = 1;
      } else {
        if (a[i] <= a[i + 1])
          continue;
        else {
          printf("%d\n", i);
          flag = 1;
          break;
        }
      }
    }
    if (flag)
      continue;
    else
      printf("0\n");
  }
  return 0;
}
