#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> vc;
    for (int i = 1; i < n; i++) {
      vc.push_back(a[i] - a[i - 1]);
    }
    int ans = 0;
    int i = vc.size() - 1;
    while (i >= 0 && vc[i] <= 0) i--;
    for (; i > 0; i--) {
      if (vc[i] >= 0 && vc[i - 1] < 0) {
        ans = i;
        break;
      }
    }
    cout << ans << "\n";
  }
}
