#include <bits/stdc++.h>
using namespace std;
bool isSolveabe(int *a, int n, int m) {
  int i = m;
  int j = n - 1;
  int min = INT_MIN;
  while (i < j) {
    if (a[i] < a[j]) {
      if (a[i] < min) {
        return false;
      }
      min = a[i];
      ++i;
    } else {
      if (a[j] < min) {
        return false;
      }
      min = a[j];
      --j;
    }
  }
  return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int s = 0;
    int e = n - 1;
    int ans = 0;
    while (s <= e) {
      int m = (s + e) / 2;
      if (isSolveabe(a, n, m)) {
        ans = m;
        e = m - 1;
      } else {
        s = m + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
