#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, n, j, a[200005], k, m = 0, l = 0, s;
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> n;
    m = 0;
    l = 0;
    for (j = 1; j <= n; j++) {
      cin >> a[j];
    }
    for (j = n; j >= 2; j--) {
      if (a[j - 1] < a[j]) {
        m++;
        s = j - 1;
        break;
      }
    }
    if (m > 0) {
      for (j = s; j >= 2; j--) {
        if (a[j - 1] > a[j]) {
          l++;
          cout << j - 1 << endl;
          break;
        }
      }
    }
    if (l == 0) {
      cout << 0 << endl;
    }
  }
  return 0;
}
