#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, A[200002];
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> A[i];
    }
    bool max_found = false;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (!max_found && i == 0)
        break;
      else if (!max_found) {
        if (A[i] <= A[i - 1]) {
        } else
          max_found = true;
      } else {
        if (A[i] <= A[i + 1]) {
        } else {
          ans = i + 1;
          break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
