#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int p[x];
    int c = 1, f = 0, temp = 0;
    for (i = 0; i < x; i++) {
      cin >> p[i];
      if (i == 0) continue;
      if (f == 0) {
        if (p[i] >= p[i - 1])
          c++;
        else {
          c++;
          f = 1;
          temp = i;
        }
      } else {
        if (p[i] < p[i - 1]) temp = i;
        if (p[i] <= p[i - 1])
          c++;
        else {
          c = (i - temp) + 1;
          f = 0;
        }
      }
    }
    cout << x - c << endl;
  }
  return 0;
}
