#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;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 1 || n == 2) {
      cout << 0 << endl;
    } else {
      int mxx = -1;
      int i = n - 1;
      for (i = n - 1; i >= 1; i--) {
        if (a[i] > a[i - 1]) {
          mxx = i;
          break;
        }
      }
      int ans = 0;
      if (mxx == -1) {
        cout << 0 << endl;
      } else {
        for (int j = mxx - 1; j >= 1; j--) {
          if (a[j] < a[j - 1]) {
            ans = j;
            break;
          }
        }
        cout << ans << endl;
      }
    }
  }
  return 0;
}
