#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const int MX = 100001;
const double epsilon = 1e-12;
const vector<vector<int> > ds = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int o = 0; o < t; o++) {
    int n;
    cin >> n;
    vector<int> vc;
    for (int i = 0; i < n; i++) {
      int k;
      cin >> k;
      vc.push_back(k);
    }
    bool inc = true;
    int i = (int)(vc).size() - 2;
    for (; i >= 0; i--) {
      if (inc) {
        if (vc[i] < vc[i + 1]) {
          inc = false;
        }
      } else {
        if (vc[i] > vc[i + 1]) {
          break;
        }
      }
    }
    printf("%d\n", i + 1);
  }
  return 0;
}
