#include <bits/stdc++.h>
using namespace std;
int st(int x, int pos) { return x = x | (1 << pos); }
int Reset(int x, int pos) { return x = x & ~(1 << pos); }
long long A[300001];
int main() {
  long long test;
  cin >> test;
  for (int cs = 1; cs <= test; cs++) {
    long long n;
    cin >> n;
    for (int i = 1; i <= n; i++) scanf("%lld", &A[i]);
    long long j = n - 1;
    while (A[j] >= A[j + 1] && j >= 0) {
      j--;
    }
    while (A[j] <= A[j + 1] && j > 0) {
      j--;
    }
    cout << j << endl;
  }
}
