#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, cnt = 0;
    cin >> n;
    vector<int> v(n);
    for (int(i) = (0); (i) < (n); (i)++) {
      cin >> v[i];
      if (i != 0 && v[i] >= v[i - 1]) cnt++;
    }
    if (cnt == n - 1)
      cout << 0 << "\n";
    else {
      int j = 1, id = 0;
      for (int i = n - 1; i > 0; i--) {
        if (v[i] <= v[i - 1])
          j++;
        else {
          id = i;
          break;
        }
      }
      for (int i = id; i > 0; i--) {
        if (v[i] >= v[i - 1])
          j++;
        else
          break;
      }
      cout << n - j << "\n";
    }
  }
}
