#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    auto check = [&](int k) {
      int l = k, r = n - 1;
      int pre = 0;
      while (l <= r) {
        if (a[l] < pre || a[r] < pre) {
          return false;
        }
        if (a[l] < a[r]) {
          pre = a[l++];
        } else {
          pre = a[r--];
        }
      }
      return true;
    };
    int l = 0, r = n, mid, res;
    while (l <= r) {
      mid = (l + r) / 2;
      if (check(mid)) {
        r = mid - 1;
        res = mid;
      } else {
        l = mid + 1;
      }
    }
    cout << res << endl;
  }
}
