#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
const long long MAXN = 1e5 + 7, MAX_OP = 3, PRIME_1 = 29, PRIME_2 = 31,
                MAX_ALPHABET = 26, INF = 1e9 + 7, MOD = 1e9 + 7, SIZE = 100,
                P = 5;
template <class T>
T sqr(T a) {
  return a * a;
}
long long bin_pow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
void solve() {
  int n, l = 0, r = 0, id = -1;
  cin >> n;
  vector<int> a(n);
  vector<pair<int, int> > b;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    if (b.size() == 0)
      b.push_back({a[i], i});
    else if (b[b.size() - 1].first != a[i])
      b.push_back({a[i], i});
    else
      b[b.size() - 1].second++;
  }
  for (int i = 1; i < b.size() - 1; ++i) {
    if (b[i] < b[i - 1] && b[i] < b[i + 1]) {
      id = b[i - 1].second;
    }
  }
  cout << id + 1 << "\n";
}
auto main() -> int {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t-- > 0) {
    solve();
  }
  return 0;
}
