#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int k = 0; k < T; ++k) {
    int n;
    cin >> n;
    bool checkAsc = true, checkDesc = true;
    vector<int> arr(n), index;
    cin >> arr[0];
    for (int i = 1; i < n; ++i) {
      cin >> arr[i];
      if (arr[i] < arr[i - 1]) checkAsc = false;
      if (arr[i] > arr[i - 1]) checkDesc = false;
    }
    int cntBot = 1, bottom = 0, asc = 0, desc = 0;
    for (int i = n - 1; i > 0; --i) {
      if (arr[i] > arr[i - 1]) {
        desc = 1;
      } else if (arr[i] < arr[i - 1]) {
        asc = 1;
        if (desc == 1) {
          bottom = i;
          break;
        }
      }
    }
    cout << bottom << endl;
  }
  return 0;
}
