#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int Tc;
  cin >> Tc;
  while (Tc--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &i : arr) cin >> i;
    auto search = [&](int idx) {
      deque<int> List(arr.begin() + idx, arr.end());
      int last = 0;
      while (!List.empty()) {
        int left = List.front();
        int right = List.back();
        if (last > min(left, right))
          return false;
        else if (left <= right) {
          List.pop_front();
          last = left;
        } else {
          List.pop_back();
          last = right;
        }
      }
      return true;
    };
    int lo = 0, hi = n - 1;
    int ans = -1;
    while (lo <= hi) {
      int mid = lo + (hi - lo) / 2;
      if (search(mid + 1)) {
        ans = mid;
        hi = mid - 1;
      } else
        lo = mid + 1;
    }
    if (ans == 0 && search(0))
      cout << 0 << '\n';
    else
      cout << ans + 1 << '\n';
  }
}
