#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  int a[150001];
  int i, n;
  int counter;
  while (t--) {
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int min = a[n - 1];
    counter = 0;
    for (i = n - 2; i >= 0; i--) {
      if (a[i] < min) {
        min = a[i];
      } else if (a[i] > min) {
        counter++;
      }
    }
    printf("%d\n", counter);
  }
  return 0;
}
