#include <bits/stdc++.h>
using namespace std;
int t, n, a[150010], MIN[150100];
int ans;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    MIN[n] = a[n];
    for (int i = n - 1; i >= 1; i--) MIN[i] = min(MIN[i + 1], a[i]);
    ans = 0;
    for (int i = 1; i < n; i++) {
      if (a[i] > MIN[i + 1]) ans++;
    }
    printf("%d\n", ans);
  }
}
