#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
int SetBit(int n, int x) { return n | (1 << x); }
int ClearBit(int n, int x) { return n & ~(1 << x); }
int ToggleBit(int n, int x) { return n ^ (1 << x); }
bool CheckBit(int n, int x) { return (bool)(n & (1 << x)); }
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int __gcd(int a, int b) {
  if (a + b == 0) return a + b;
  if (a % b == 0) return b;
  return __gcd(b, a % b);
}
long long fact(int n) {
  long long res = 1;
  for (int i = 2; i <= n; i++) {
    res = res * i;
  }
  return res;
}
long long nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
long long nPr(int n, int r) { return fact(n) / fact(n - r); }
class myComp {
 public:
  bool operator()(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
  }
};
int func(int a, int b, int c, int d) {
  vector<int> v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  v.push_back(d);
  sort((v).begin(), (v).end());
  return (v[1] + v[2]) / 2;
}
void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  if (n <= 2) {
    cout << 0 << "\n";
    ;
    return;
  }
  int dec = 1;
  int inc = 0;
  int i = n - 1;
  for (i = n - 1; i >= 1; i--) {
    if (dec) {
      if (arr[i] <= arr[i - 1]) {
        continue;
      } else {
        dec = 0;
        inc = 1;
      }
    }
    if (inc) {
      if (arr[i] >= arr[i - 1]) {
        continue;
      } else {
        break;
      }
    }
  }
  cout << i << "\n";
  ;
  return;
}
int32_t main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
