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